Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

trim all characters except "1234567890" and "+" from a string

hi!
i would like to trim all characters from a string, except "123456789" and "+"...
i need the code in lotus script only...
thx
0
MasterBlaster3000
Asked:
MasterBlaster3000
  • 4
  • 2
1 Solution
 
ZvonkoSystems architectCommented:
What do you mean with TRIM?

Normally is trim reserved for removing leading and trailing characters.
But from your question I read you like to remove all digits and the plus character from a string.
Is this what you want?

0
 
AndrewJayPollackCommented:
------------------------------
this is the most flexible way to do it.
by defining the valid characters in a string,
you can change them easily.  The function
does the work so you can use it over and over.
------------------------------
You should up the points to 100 and assign an "A"
for this great work!
------------------------------

const validchars = "123456789+"
originalstring = "a;sldkfja;s218239871a;ksdf"
cleanstring = stripallbutchars(originalstring, validchars)

------------------------------
Uses this function:
------------------------------

Function stripallbutchars(source as string, keepchars as string)as string

dim x as integer
for x = 1 to len(source)
  if instr(source, mid$(source, x, 1)) > 0 then stripallbutchars = stripallbutchars + mid$(source, x, 1)
next x

end function
0
 
AndrewJayPollackCommented:
note: there are technically faster ways to do that function, particularly if you're going to do it thousands of times in a row, or to a REALLY REALLY long text string, however this is the simplest and doing it on a sentence or two (even a paragraph or two) you'd never notice a difference.

One faster way (but less flexible) would be like this, but its hardcoded and less flexible:

originalstring = "a;sldkfja;s218239871a;ksdf"
cleanstring = stripallbutchars(originalstring)

Function stripallbutchars(source as string)as string

dim x as integer
dim a as string
for x = 1 to len(source)next x
  a = mid$(source,x,1)
  select case a
   case "1" : stripallbutchars = stripallbutchars + a
   case "2" : stripallbutchars = stripallbutchars + a
   case "3" : stripallbutchars = stripallbutchars + a
   case "4" : stripallbutchars = stripallbutchars + a
   case "5" : stripallbutchars = stripallbutchars + a
   case "6" : stripallbutchars = stripallbutchars + a
   case "7" : stripallbutchars = stripallbutchars + a
   case "8" : stripallbutchars = stripallbutchars + a
   case "9" : stripallbutchars = stripallbutchars + a
   case "+" : stripallbutchars = stripallbutchars + a
end function
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AndrewJayPollackCommented:
Let me guess, masterblaster3000 (must be from Mad Max, right?) that you're using this for a phone number field, outside the United States?
0
 
AndrewJayPollackCommented:
ACKK!!

I screwed up my first one:  use this instead:

Function stripallbutchars(source as string, keepchars as string)as string

dim x as integer
for x = 1 to len(source)
 if instr(keepchars, mid$(source, x, 1)) > 0 then stripallbutchars = stripallbutchars + mid$(source, x, 1)
next x

end function
0
 
MasterBlaster3000Author Commented:
hi Andrew,
yes, your guess was right, it is from madmax AND im using the code for german phone fields(we only have numerical chars in phone numbers)...
im sorry i cannot up the points to 100(i would like too, for sure) since i just got 75 points(but you ill give you an "A" anyway).
thx very much andrew!
0
 
MasterBlaster3000Author Commented:
thx andrew!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now