Skip to main content
13-Aquamarine
February 22, 2026
Solved

remove blank characters in a string

  • February 22, 2026
  • 1 reply
  • 133 views

I would write a function to remove blank characters in rename the string.  See attached.

Best answer by Werner_E

We can turn my approach to a function where you can select the character to delete

grafik.png

 

Or we could also create a function to replace one character for another one (empty string means delete)

grafik.png

 

And here is a string trimmer using "search" and "substr" as you had tried to do

grafik.png

Note that this approach will not work OK if ORIGIN is set to a value different from zero AND the calculation option "ORIGIN in  Strings" is set (which is usually is not by default).

 

Prime 11 file attached

1 reply

25-Diamond I
February 22, 2026

I think its easier to convert the string into a vector using "str2vec", trim all occurrences of spaces (ASCII 32) and convert back to a string:

grafik.png

This approach fails in three cases: when the string is an empty string or when it does not contain any spaces (in which case “match” fails), or when the string consists exclusively of spaces (in which case “trim” fails).
For a general helper function, these error cases should therefore be handled. For example:

grafik.png

Or a little bit shorter

grafik.png

 

13-Aquamarine
February 22, 2026

Thank you,

 

I was trying another approach, was working a long hand that I was going to put in program form. (see attach).  Your approach is much more superior.

 

 

 

Werner_E25-Diamond IAnswer
25-Diamond I
February 22, 2026

We can turn my approach to a function where you can select the character to delete

grafik.png

 

Or we could also create a function to replace one character for another one (empty string means delete)

grafik.png

 

And here is a string trimmer using "search" and "substr" as you had tried to do

grafik.png

Note that this approach will not work OK if ORIGIN is set to a value different from zero AND the calculation option "ORIGIN in  Strings" is set (which is usually is not by default).

 

Prime 11 file attached