Delai Posted Friday at 10:10 PM Posted Friday at 10:10 PM (edited) Hi, and thqnks in advance for your help, The string is found five times in the same line. The problem is that the stringreplace always changes the first string founded. The Line in question before the changes is: En un estudio sobre la presencia de mujeres en las empresas tecnológicas se observa que el 20 % de los operarios, el 40 % de los ingenieros y el 30 % de los directivos son mujeres. Se sabe que en estas empresas el 20 % de las plantillas son directivos, el 35 % son ingenieros y el resto son operarios. Se elige un trabajador al azar de una de estas empresas. After the changes, the result is: En un estudio sobre la presencia de mujeres en las empresas tecnológicas se observa que el 20 \\\\\% de los operarios, el 40 % de los ingenieros y el 30 % de los directivos son mujeres. Se sabe que en estas empresas el 20 % de las plantillas son directivos, el 35 % son ingenieros y el resto son operarios. Se elige un trabajador al azar de una de estas empresas. For $j = 1 to $CountLinesTest IF StringInStr ($LineTest, "€") OR StringInStr ($LineTest, "%") THEN $sString = StringStripWS($LineTest, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) $Line_Split = StringSplit($sString, " ") For $i=1 to $Line_Split[0] Select Case .... Case StringInStr ($Line_Split[$i], "%") IF $Line_Split[$i] == "%" AND $i > 1 AND StringRegExp($Line_Split[$i-1], "^\d*\.?\d+$") THEN $Replace = StringReplace($LineTest, $Line_Split[$i], "\%", 1) _FileWriteToLine($FileTest, $j, $Replace, 1) $LineTest = $Replace ELSEIF ...... ELSEIF ........ ENDIF EndSelect NEXT ENDIF NEXT Edited Friday at 10:13 PM by Delai
Musashi Posted Friday at 11:15 PM Posted Friday at 11:15 PM (edited) Could you please : 1. Briefly describe what you want to replace by what. 2. Post a runnable example script. Since you write : 1 hour ago, Delai said: After the changes, the result is: ... you must have a working one. Edited Friday at 11:16 PM by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
pixelsearch Posted yesterday at 02:21 AM Posted yesterday at 02:21 AM (edited) @Musashi hello I think OP wants to replace each "%" (preceded with digits & eventual dot) with "\%" while keeping a log of each replacement using _FileWriteToLine . But maybe not all "%" must be processed, as we'll see in the script below. @Delai I tried another approach, because the way you scripted it (by splitting the sentence) makes it hard to find the position you need in the original sentence, when comes the replacement part. Local $sLineIn, $sLineOut, $sPattern, $nMode, $iOffset, $aArray $sLineIn = "This % sign for test (not preceded with digits) . " & _ "En un estudio sobre la presencia de mujeres en las empresas tecnológicas se observa que el 20 % de los operarios, " & _ "el 40 % de los ingenieros y el 30 % de los directivos son mujeres. Se sabe que en estas empresas el 20 % de las plantillas " & _ "son directivos, el 35 % son ingenieros y el resto son operarios. Se elige un trabajador al azar de una de estas empresas." $sPattern = '(?U).*\d*\.?\d+ *(%).*' $nMode = 2 ; $STR_REGEXPARRAYFULLMATCH $iOffset = 1 While 1 $aArray = StringRegExp($sLineIn, $sPattern, $nMode, $iOffset) If @error Then $sLineOut &= StringMid($sLineIn, $iOffset) ExitLoop EndIf $iOffset = @extended $sLineOut &= StringTrimRight($aArray[0], 1) & "\%" ; your _FileWriteToLine here WEnd MsgBox(0, "$sLineOut", $sLineOut) Hope it helps Edited yesterday at 02:22 AM by pixelsearch typo Musashi 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
Delai Posted 13 hours ago Author Posted 13 hours ago @Musashi Sorry, I want to replace % with \% when are variuos in the same line like has described @pixelsearch @pixelsearch Thank you very much for your help. I will try your approach;
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