Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eliminating special characters 2

Status
Not open for further replies.

paul102384

Programmer
Oct 5, 2007
30
0
0
hi to all pb programmers:

Is there an available function that can eliminate any special characters like commas (,),apostrophes ('), colons :)), semi-colons (;), periods (.), etc... and also the charcter (ñ).... in a string?

e.g J. VARGAS AVE.,

how can i eliminate the special charcters like period(.) and comma(,) in the example given?

thanks in advance....
 
We use our own user functions for this. Something like this:

/*--USER FUNCTION: uf_condense( as_in as String ) Returns String--*/

String ls_char, ls_out
Long ll_pos

FOR ll_pos = 1 TO Len( as_in )
ls_char = Mid( as_in, ll_pos, 1 )
IF ls_char >= 'A' AND ls_char <= 'Z' THEN
ls_out += ls_char
ELSEIF ls_char >= 'a' AND ls_char <= 'z' THEN
ls_out += ls_char
END IF
NEXT


RETURN ls_out


Just keep adding in special characters to include in the ELSEIF's. Hope this helps!
 
here is a more generic function whis can do mor. not just eleiminate some characters but also replace characters for a in string

public function string of_replace (string as_string, string as_token, string as_replace);

string ls_text = ""

long ll_count, ll_n, ll_token, ll_pos, ll_start, ll_replace

IF IsNull( as_string) THEN as_string = ""
IF IsNull( as_token) THEN as_token = ""
IF IsNull( as_replace) THEN as_replace = ""

ll_start = 1
ll_token = len( as_token)
ll_replace = len( as_replace)
ls_text = as_string
ll_pos = Pos( ls_text, as_token, ll_start)
//-----------------------------------------------
//ll_pos = Pos( lower( ls_text), lower( as_token), ll_start)
// use this for a case - INSENSITIVE search/replace
//-----------------------------------------------
DO WHILE ll_pos > 0
ls_text = Replace( ls_text , ll_pos, ll_token, as_replace)
ll_start = ll_pos + ll_replace
ll_pos = Pos( ls_text, as_token, ll_start)
//-----------------------------------------------
//ll_pos = Pos( lower( ls_text), lower( as_token), ll_start)
// use this for a case - INSENSITIVE search/replace
//-----------------------------------------------
LOOP

RETURN ls_text

e-g. to eleiminate "." "," and ";" from a string use

new_string = of_replace ( old_string, ".", "")
new_string = of_replace ( new_string, ",", "")
new_string = of_replace ( new_string, ";", "")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top