Jump to content

best way to do this?


Recommended Posts

  • Developers

$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)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
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

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

Edited by n9mfk9
Link to comment
Share on other sites

  • Moderators

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).

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...