Sign in to follow this  
Followers 0
heibel

StringWordReplace?

4 posts in this topic

#1 ·  Posted (edited)

Hello there, I'm a bit stuck on this...

I have a string like this: (includes words and @CR's etc)

$mystring="

bla bla

www.mysite.org

bla bla

<A HREF="http://www.mysite.org">www.mysite.org</A>

please visit: www.mysite.org bla bla

bla bla..

"

So, I want to do a search&replace for each word of $mystring,

$wordcount=words($mystring); using rex00.au3 (or something)

it means:

word1: bla

word2: bla

word3: www.mysite.org

word4: bla

word5: bla

word6: <A

word7: HREF="http://www.mysite.org">www.mysite.org</A>

word8: please

word9: visit

word10: www.mysite.org

etc.

SO:

For $y=1 To $wordcount

$string=Word($mystring,$y)

;check for:

If StringLeft ($string,4)=="www." Then

Replace it by something like:

$mystring=StringReplace($mystring,$string,"<A HREF=""java script:parent.LinkNewMax('"&$string&"')"&""""&">"&$string&"</A>",1)

Next

Okay, so this is working great as long as there is only on occurence of www.mysite.org ( which in this case is not)

What I need is something like:

StringReplaceWord($mystring,$string,"<A HREF=""java script:parent.LinkNewMax('"&$string&"')"&""""&">"&$string&"</A>")

PS. I was also thinking of a StringReplace(,,,1 time only,from the right)

Or something?

I'm sure someone can learn me something! Thanks in advance.

Harry

Edited by heibel

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

OK, there's a few things in this post:

1- I'm sure that you're actually defining $string with a function rather than declaring it, but what you're actually storing as $string in the above post is something more like:

$mystring=@CRLF & "bla bla" & @CRLF & www.mysite.org & @CRLF & "bla bla" & @CRLF & "<A HREF=""www.mysite.org""></A>" & @CRLF & "please visit: www.mysite.org bla bla" & @CRLF & "bla bla.." & @CRLF
oÝ÷ Ûbj}ý¶×¥'ò¢èZ½ëaÌ(®H§ç¢×ë¢l¨ººh²Öî¶Ø^­íý²Ø^±ç-ðêÞÊyø§{MúÂÝr§µ«0¢·lÓ~¦ÊËkx¢"Ú.²)àJÚâ©+eG¬¡«­¢+Ø(ÀÌØíݽÉÌõMÑÉ¥¹MÁ±¥Ð ÀÌØíµåÍÑÉ¥¹°ÅÕ½ÐìÅÕ½Ðì¤(oÝ÷ ØÚ0Êjw(ا¹è§¶¨º·è®Z(¦ÉbeÊjøu«­¢+Ø)½ÈÀÌØíäôÄѼÀÌØíݽÉÍlÁtìÀÌØíݽÉÍlÁt¥Ìѡ͵Ìå½ÕÈÀÌØíݽɽչа¹Ý½ÉÄ¥ÌÍѽɥ¸ÀÌØíݽÉÍlÅt°Ý½ÉÈ¥ÌÍѽɥ¸ÀÌØíݽÉÍlÉt°Ñ(%MÑÉ¥¹1Ð ÀÌØíݽÉÍlÀÌØíåt°Ð¤ôÅÕ½ÐíÝÝܸÅÕ½ÐìQ¡¸ÀÌØíݽÉÍlÀÌØíåtôÅÕ½Ðì±Ðí!IôÅÕ½ÐìÅÕ½Ðí©ÙÍÉ¥ÁÐéÁɹй1¥¹­9Ý5à ÌäìÅÕ½ÐìµÀìÀÌØíݽÉÍlÀÌØíåtµÀìÅÕ½ÐìÌäì¤ÅÕ½ÐìµÀìÅÕ½ÐìÅÕ½ÐìÅÕ½ÐìÅÕ½ÐìµÀìÅÕ½ÐìÐìÅÕ½ÐìµÀìÀÌØíݽÉÍlÀÌØíåtµÀìÅÕ½Ðì±Ðì½ÐìÅÕ½Ðì(%MÑÉ¥¹1Ð ÀÌØíݽÉÍlÀÌØíåt°Ð¤ôÅÕ½Ðí± ÅÕ½ÐìQ¡¸ÀÌØíݽÉÍlÀÌØíåtôÅÕ½ÐíͽµÑ¡¥¹Ñ¼ÉÁ±± ÅÕ½Ðìí©ÕÍн¹½Ñ¡Í±¥¹Ì½È ½å½ÕÈÅÕ½Ðí¥Ñ¡ÍÑÉ¥¹¥ÌQ!%L°Ñ¡¸ÉÁ±¥ÐÝ¥Ñ Q!PÅÕ½Ðì½¹¥Ñ¥½¹Ì)9áÐ(oÝ÷ Ù*"·¥È^rF¥*.­Ê'v+{¢·¯z¼°¢·ZÛayªëk+-¢·}7ë
+"VÞjYmêÞ¦VyÛ-®)à°Ú0Ê£ºËgyçm¢·²Ç¦nW²¢ê춸§«­¢+Ø(ÀÌØíIÁ±MÑÉ¥¹ôÅÕ½ÐìÅÕ½Ðì)½ÈÀÌØí¤ôÄѼÀÌØíݽÉÍlÁt(ÀÌØíIÁ±MÑÉ¥¹ôÀÌØíIÁ±MÑÉ¥¹µÀìÀÌØíݽÉÍlÀÌØí¥tµÀìÅÕ½ÐìÅÕ½Ðì)9áÐ(oÝ÷ ØÚ0ÊÛ©Â+aÊ«²Úâî·­Þ{kjÊZq歶Ѷ¸¡ø­¶¬jëh×6
$ReplacedString = StringLeft($ReplacedString,StringLen($ReplacedString)-1)

That just tells it to store $ReplacedString as the entire string except for the very last character.

Does that get you closer to your answer? There's no need to have a StringReplaceWord() function, because just plain ol' StringReplace() will replace whole words, and if you StringSplit() the string apart based on spaces, then there's no danger of it replacing more than that word per each occurance.

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

That just tells it to store $ReplacedString as the entire string except for the very last character.

Does that get you closer to your answer? There's no need to have a StringReplaceWord() function, because just plain ol' StringReplace() will replace whole words, and if you StringSplit() the string apart based on spaces, then there's no danger of it replacing more than that word per each occurance.

Hello james3g,

I see you point! I think I can figure this approach and get it working.

A bit dissapointed though, since I have the feeling it can be pretty slow (imagine one full A4-page of text)

Question as well!!!!

The StringSplit using " " (=a space):

Does it also works with one word on one single line???

My feeling: I have to StringSplit using both " " As @CR(LF)"

Thanks anyway!

Harry

Share this post


Link to post
Share on other sites

Probably...forgot about that :whistle:

Try

$words=StringSplit($Thestring," "&@LF)

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0