Sign in to follow this  
Followers 0
n9mfk9

best way to do this?

8 posts in this topic

HI all

I am stuck here

here is my test code

$test5 = "test" & @CR &"test" & @CR &"test"
$test6 = StringInStr($test5,"test",0,3)
StringReplace ($test6,"ok",1)
MsgBox(0,"test5",$test5)

what i went to do is change the 3rd test to ok an not change the first or second thanks beau

Share this post


Link to post
Share on other sites



$test5 = "test" & @CR & "test" & @CR & "test"
$test6 = StringInStr($test5, "test", 0, 3)
If $test6 Then
    $test5 = StringLeft($test5,$test6-1) & "ok" & StringMid($test5,$test6 + 4)
EndIf
MsgBox(0, "test5", $test5)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Func _StringReplaceInstance($sString, $sReplace, $sReplaceWith, $iInstance, $iCase = 0)
    Local $iSnS = StringInStr($sString, $sReplace, $iCase, $iInstance)
    If $iSnS = 0 Then Return SetError(1, 0, '')
    Return StringLeft($sString, $iSnS -1) & $sReplaceWith & StringTrimLeft($sString, $iSnS + (StringLen($sReplace) - 1))
EndFunc

Edit

Hmm... I didn't even notice that Jdeb had responded 10 minutes ago!! (Senility?)

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Func _StringReplaceInstance($sString, $sReplace, $sReplaceWith, $iInstance, $iCase = 0)
    Local $iSnS = StringInStr($sString, $sReplace, $iCase, $iInstance)
    If $iSnS = 0 Then Return SetError(1, 0, '')
    Return StringLeft($sString, $iSnS -1) & $sReplaceWith & StringTrimLeft($sString, $iSnS + (StringLen($sReplace) - 1))
EndFunc

Edit

Hmm... I didn't even notice that Jdeb had responded 10 minutes ago!! (Senility?)

Hi

the both worked there was one thing once i do the 3rd 1 i went to do every on from there on

how wood i do it

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi

the both worked there was one thing once i do the 3rd 1 i went to do every on from there on

how wood i do it

You've been here for how long?

Something like:

$sTemp = $sString
While 1
    $sString = _StringReplaceInstance($sString, 'test', 'ok', 3)
    If @error Then ExitLoop
    $sTemp = $sString
WEnd
$sString = $sTemp

Func _StringReplaceInstance($sString, $sReplace, $sReplaceWith, $iInstance, $iCase = 0)
    Local $iSnS = StringInStr($sString, $sReplace, $iCase, $iInstance)
    If $iSnS = 0 Then Return SetError(1, 0, '')
    Return StringLeft($sString, $iSnS -1) & $sReplaceWith & StringTrimLeft($sString, $iSnS + (StringLen($sReplace) - 1))
EndFunc
?

Edit: the example I had wouldn't work... from before.

Edit2:

It would be much simpler if we used StringRegExpReplace... but I didn't figure out the right syntax for it.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

the example from before wood only do the 3rd line

i was try to start at 3rd line an replace every line there an after

I was thinking StringRegExpReplace but could not fat a way for it to start on the 3rd line

Edited by n9mfk9

Share this post


Link to post
Share on other sites

the example from before wood only do the 3rd line

i was try to start at 3rd line an replace every line there an after

Did you bother to run the above? Sometimes I wonder where in the hell this forum is going... from stupid ass titles with no descriptions to people that put forth no effort on their own (or if they do they don't show it).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

thanks for all the help that did it

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