Delai Posted 11 hours ago Posted 11 hours ago (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 11 hours ago by Delai
Musashi Posted 10 hours ago Posted 10 hours ago (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 10 hours ago 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 6 hours ago Posted 6 hours ago (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 6 hours ago by pixelsearch typo Musashi 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
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