Connecting Tech Pros Worldwide Forums | Help | Site Map

Is there a way to split the contents of a string?

Newbie
 
Join Date: Nov 2008
Posts: 7
#1: Nov 18 '08
I have a string of the form '_10_245_' of varchar type to represent a list of integers.

Is there a way to extract the numbers out of that string?

examples of the string:

'_34_'

'_123_78_'

'_34_155_134_'

I manged to convert the string into the form of '34 155 134' using replace , ltrim and rtrim...but what should I do next?How can I split that string? As soon as I do that, I will convert each substring into int using the cast function.

Also note that the string it's not always the same; there's a column in a table containing those strings as its values.

Each of those numbers is a code and exists in another table A in an int column. Table A also provides each code's description in a varchar column.

I want to match each number in my string to its description in table A.

Any suggestions?

Thanks in advance

ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Nov 18 '08

re: Is there a way to split the contents of a string?


You have a "_" delimited string.

Option 1:

Parse it with a lot of substring or loop.

Option 2:
Use this technique.

-- CK
Reply