Suppir Posted December 8, 2009 Posted December 8, 2009 (edited) Hello! I have the code: for $i = 0 to UBound($Search) - 1 $Text = StringRegExpReplace($Text, $Search[$i][0], $Search[$i][1]) Next $Search[$i][0] - is a regular exression to search $Search[$i][0] - is a text to replace founded How to cut out the founded if my $Search[$i][1] defined but equals "nothing"? (not assigned any value) In this situation replace does not work. Edited December 8, 2009 by Suppir
picaxe Posted December 8, 2009 Posted December 8, 2009 Try $Text = StringRegExpReplace($Text, $Search[$i][0], "'" & $Search[$i][1] & "'")
Suppir Posted December 8, 2009 Author Posted December 8, 2009 Try $Text = StringRegExpReplace($Text, $Search[$i][0], "'" & $Search[$i][1] & "'") In this situation script prints many many quotes '
picaxe Posted December 8, 2009 Posted December 8, 2009 Maybe If $Search[$i][1] = "" Then $Text = StringRegExpReplace($Text, $Search[$i][0], '') Else $Text = StringRegExpReplace($Text, $Search[$i][0], $Search[$i][1]) EndIf
Suppir Posted December 8, 2009 Author Posted December 8, 2009 (edited) Maybe If $Search[$i][1] = "" Then $Text = StringRegExpReplace($Text, $Search[$i][0], '') Else $Text = StringRegExpReplace($Text, $Search[$i][0], $Search[$i][1]) EndIf I've try it before but it does not work too. In this situation replace does not work at all. Edited December 8, 2009 by Suppir
Malkey Posted December 8, 2009 Posted December 8, 2009 Hello! I have the code: for $i = 0 to UBound($Search) - 1 $Text = StringRegExpReplace($Text, $Search[$i][0], $Search[$i][1]) Next $Search[$i][0] - is a regular exression to search $Search[$i][0] - is a text to replace founded How to cut out the founded if my $Search[$i][1] defined but equals "nothing"? (not assigned any value) In this situation replace does not work. Local $sRes Local $sText = " The cat sat on the mat." Local $aSearch[4][2] = [["cat", "dog"],["the", "a"],["mat", "rug"],["sat ", ""]] $sRes = $sText & @CRLF For $i = 0 To UBound($aSearch) - 1 $sText = StringRegExpReplace($sText, $aSearch[$i][0], $aSearch[$i][1]) $sRes &= $sText & @CRLF Next MsgBox(0, "StringRegExpReplace", $sRes) ;ConsoleWrite($sRes & @CRLF) The expected results obtained from this example is:- The cat sat on the mat. The dog sat on the mat. The dog sat on a mat. The dog sat on a rug. The dog on a rug. Note - The default, case-sensitivity, is working. eg. Match on "the" but no match on "The" I hope this example helps you realize why your script is not performing as you expect.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now