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

How can I split a text string on special characters? 1

Status
Not open for further replies.

steela

Programmer
Sep 2, 2003
6
BE
Hi,

I'd like to split a text string on a special character...

e.g.
text=mkt_service+prox+n
var1=FUNC(text,'+',1)
echo var1
var2=FUNC(text,'+',2)
echo var2
var3=FUNC(text,'+',3)
echo var3

should give the output:
mkt_service
prox
n

Does anyone have any ideas on what the 'FUNC', or equivalent coding that does the same, could be?

Thanks!

Aimee
 
Although I like Ygor's solution better than mine, you can also use these functions in the Korn shell...
Code:
TEXT=mkt_service+prox+n
VAR1=${TEXT%%+*}
VAR2=${TEXT#*+} ; VAR2=${VAR2%+*}
VAR3=${TEXT##*+}
These are string trimming functions in the Korn shell.

But, like I said, Ygor's is simple and easy to extend. Too cool! (Star!)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top