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
MasterBlaster3000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.