Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
HI Team,
I have one requirement in my current project, which I need to replace some customized words in the elements where it is present in whole document.The below peace of code facing some issues on replacing the words.
function checkWord(word,color){
local rtn = 1;
local logmsg = oid_first();
# Set disable continue search
set wrapscan = off;
# Cursor goto root of document
goto_oid(oid_caret());
# Find word & changing text color
while(rtn == 1) {
rtn = find(word, 0x0008|0x0200|0x0020);
if(rtn == 1) {
selectText = main::selection;
EditDelete;
str = '<?Pub _font FontColor="'.$color.'" ?>'.selectText.'<?Pub /_font?>';
#insert(str);
local findWithin; findWithin = V['FindWithin'];
local replFlags = flags|0x0020
replace(word, insert(str), replFlags, findWithin, current_doc())
}
}
}
example doc : -
<SimpleText>
<para>Be aware of the fire hazard, especially when working near flammable substances or vapours</para>
<para2>I am WelCome you vapours</para2>
</SimpleText>
After Replacing the out put the doc
<SimpleText>
<para>Be aware of the fire hazard, especially when working near flammable substances or vapours</para>
<para2>I am WelCome you 1</para2> // here word vapours is replaced with one.
</SimpleText>
Could you please any one do some need full help on this.
Thanks
Prashant
Solved! Go to Solution.
To limit the search to full words, change the flag in the replace() function from 0x2010 to 0x2018. (You can find a full description of the flag parameter in the online documentation for the replace() function.)
--C
Hi Prashant--
You're really overthinking this. The built-in replace() function will handle the entire operation you are trying to accomplish.Try something like this:
replace("vapours",'<?Pub _font FontColor="Red"?>vapours<?Pub /_font?>",0x2010,"para2");
By this, I mean replace *all* of your code above with this single line. If I read your description correctly, this should do everything you need modifying all instances of "vapours" within <para2> throughout the document.
--Clay
Thanks for your immediate response, If you see the code which the function checkWord(word,color) contains two arguments I am passing word and colour are dynamic values , every time the value will not same just like "vapours". As you suggested in the mail should I pass dynamic value as "vapours" in the line replace("vapours",'<?Pub _font FontColor="Red"?>vapours<?Pub /_font?>",0x2010,"para2"); but here para2 will not be very time the same it could be any thing there then how should I handle it.
thanks,
prashant
Hi Prashant--
Yes, of course, those are parameters you can modify as you need to, or use variable values for as you normally would. For convenience, you can define a custom function to simplify the parameterization. For example, you could write a function like this:
function highlightWord(word, color, context) {
replace(word,'<?Pub _font FontColor="' . color . '"?>' . word . "<?Pub /_font?>",0x2010, context);
}
Then you just call this function and pass it the text you want to replace (the "word" parameter), the color you want to make it, and the name of the element you want to search within (the "context" parameter).
--Clay
Thanks Clay, I will try this as suggested.
Thanks,
prashant
HI Clay , this is not working for me , giving exception vapours is not a element. is there any another way to handle this.
Thanks,
prashant
You must be passing the parameters in the wrong order, i.e. the word "vapours" as the last parameter, which should be the name of the element that you want to scan within. If you call it like this:
highlightWord("vapours", "red", "para")
it will highlight all instances of "vapours" within a <para> element, and make them red.
--Clay
Thank you very much clay , it worked, but when I replacing the word with color. in example "or" is word which present in <para>. In word working there 'or' also is considering as a word and coloring any idea to how to control this, I have tried but not able to sort it out. or how to find the position of a word in the document..
<SimpleText>
<para>Be aware of the fire hazard, especially when working near flammable substances or vapours</para>
<para2>I am WelCome you vapours</para2>
</SimpleText
Thanks,
Prashant
To limit the search to full words, change the flag in the replace() function from 0x2010 to 0x2018. (You can find a full description of the flag parameter in the online documentation for the replace() function.)
--C
HI Clay, I tried with all the flags given in support on-line doc which related to my scenario , and also tried with some other scenarios but I dint find any think that give solution for me. I am trying to replace the word based on position of a word in document, but I don't have clear information which function to use for finding the position of a word in document and also following the on-line doc too. Could you please suggest any example so that I can try in that way.
Thanks,
Prashant
Hi Prashant--
I guess your requirement isn't clear, because when I run this with the 0x2108 flag, it works the way I expected (and the way I thought you wanted it to), by highlighting instances of "or" when it's a standalone word, but not in the middle of another word.
I'm sorry, but I don't really have any more time to spend on this. I try to be helpful to the community by answering questions on this list when I can, but developing Arbortext solutions is what I do for a living. This thread is beginning to be less like an answer to a question and more like a consulting engagement.
My company offers comprehensive consulting services as well as Arbortext training. If you would like to consider engaging us on a formal basis to provide training, mentoring, or solution development, please let me know and I'll put you in touch with our business development staff.
Good luck with your project. The best advice I can give you is to keep trying different approaches until you find one that works.
--Clay
Thank you very much Clay for spending your valuable time for this, I will try for that what you suggested, thanks a lot.
Prashant
Hello Clay,
Could you please guide me with the process to contact business development staff..
Also, could you please provide me some high level information regarding contract & pay so that it would be handy.
Thanks & Regards
Prashanth
Hi Prashant--
I will send you this info in a private message.
--Clay
Thanks Clay , when can I expect this info.
Regards
Prashant
Hello Clay,
We are awaiting your reply. Could, you please share me the requested information at the earliest..
Also, please guide me about Partner Advantage program (Silver).
Thanks,
Prashant
Hi Prashant--
Please check your direct messages in the PTC Community. I responded with a private message shortly after I posted here.
If you can't find that message, give me your email and I will send the information there.
--Clay
Hi Clay,
Sorry, I can't find that, could you please pass the same to this mail id prashant.meesala@valuelabs.com
Thanks,
Prashant