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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search and replace

Status
Not open for further replies.

TimRHSD

Programmer
Apr 18, 2002
35
US
Is there a function or does someone have one written which searches for a substring within a string and replaces it with another?
e.g. MyString = "MyLastName, Tim",
MySearchString = ","
MyReplaceStr = " "

The result being "MyLastName Tim"
 
Tim:

I'm not sure of the online version where informix introduced the replace function -probably 7.x. I'm sure it wasn't there in 5.x.

From Ron Flannery's, The Informi Handbook:

"The REPLACE function replaces characters within a string with different characters. The syntax for this function is:

REPLACE(input string, old_string, new_string where:

input_string is the string you want to replace.

old_string are the characters with input_string that you want to replace

new_string is the string with which you want to replace old_string"

unquote

Here's a nonsensical example you can execute from dbaccess/isql:

create temp table names (
mystring char (80)
);
insert into names values ("MyLastName, Tim");
select mystring, replace(mystring, ",", "") from names;
drop table names;

This is probably what you want. As an old Informix 4GL programmer, I developed a replace string function, but, obviously, it's useless unless you're using 4GL. It's yours for the asking.

Regards,

Ed
Schaefer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top