?
Solved

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

Posted on 2003-03-06
7
Medium Priority
?
237 Views
Last Modified: 2013-12-18
hi!
i would like to trim all characters from a string, except "123456789" and "+"...
i need the code in lotus script only...
thx
0
Comment
Question by:MasterBlaster3000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 8081168
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
 
LVL 5

Expert Comment

by:AndrewJayPollack
ID: 8081185
------------------------------
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
 
LVL 5

Expert Comment

by:AndrewJayPollack
ID: 8081223
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:AndrewJayPollack
ID: 8081258
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
 
LVL 5

Accepted Solution

by:
AndrewJayPollack earned 300 total points
ID: 8081274
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
 

Author Comment

by:MasterBlaster3000
ID: 8081323
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
 

Author Comment

by:MasterBlaster3000
ID: 8081340
thx andrew!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question