Remove special characters from string

Derek Chan shared this question 3 years ago
Answered

E.g. text= "001.2.3"

I want to have a result of text= "00123"


My thought is: First use a sequence to store every single character, that replace every position with "." to "".

So, I write the attached ggb file, but it doesn't work with the REPEAT code:

SetValue(index, 1)

Repeat(Length(templist), If(templist(index)==".", SetValue(templist, index, "" ) ), SetValue(index, index+1))

Can someone correct my mistake?? Many thanks

Comments (10)

photo
2

Note:

The command Repeat() do not what the name say (it's an impostor)

The bigest problem are conditions.

Repeat(<count>, Execute(<script-list>)) works in te moste situations.

====================================================

to your target

You can use the operator back-slash (\) in combination with Unicode-Commands

UnicodeToText(TextToUnicode("001.2.3") \ TextToUnicode(".")) --> "00123"

photo
1

Thanks your help~ But why the repeat() can"t do it?

Repeat( <Number>, <Scripting Command>, <Scripting Command>, ... )Repeats the execution of scripting commands n times, where n is the given Number.<--that's exactly what is does in the description.

photo
2

SetValue(count,0)

Repeat(<number>,SetValue(count, count+1), Execute(<script-list>,count))

see also my first post (updated) in this thread.

=======================================

Repeat is the ugliest of all possible solutions for the given objective.

alternatives: back-slash or KeepIf() or Sequence()

photo
2

I have update above.

photo
1

Bonjour,

1) Quand je saisie : Take(textIN,%1,%1), il me dit :"saisie invalide".

a) Pourquoi met-on %1,%1?


2) La commande Take ou Trier ou Extraite (calcul formel) semble ne pas fonctionner comme indiqué ici


https://wiki.geogebra.org/e...

3) Comment traduire en français


scrTxt={"If(Take(textIN,%1,%1)!=" + u34 + "." + u34 + ",SetValue(textOUT, textOUT+Take(textIN,%1,%1)))"}

photo
1

Question: Does my version work in your environment?

If no: what is your environment.

If yes: what is the difference between my version and yours

Note: I tested without problems in Windows 10, Chrome, GGB6.0 WEB and GGB5.0.574

-----------------------

1a) %1 is the current position in the calling Repeat(). The current position is passed as the first parameter to the script list with Execute(<script-list>,<first parameter>). This first paramter is addressed in the script-list with %1.

Take(textIN,%1,%1) mean: character of actual position in textIN with length 1

2) check this sample in the manual: Take( <Text>, <Start Position>, <End Position> )

3) a script list cannot be translated. It must be written in US English.

photo
1

Thank you for your clears explanations.

All work correctly.

photo
photo
3

BTW we'll probably add a new command ReplaceAll("001.2.3",".","") soon to do this

photo
1

That would be too great to help in many codes~~!!!

photo
1

could be more great ReplaceAll(<text>,<old>,<new>,<except>)

ie: ReplaceAll("\left{001.2.3\.",".","","\.")

photo
© 2023 International GeoGebra Institute