Find space in string

How can I find specific  position of each space? Sample: This is a test only.
VBdotnet2005Asked:
Who is Participating?
 
BanthorConnect With a Mentor Commented:
Treat yourself to fn_split
Declare @S Varchar(max)
Select @S='How can I find specific  position of each space? Sample: This is a test only.'

declare @p int

Select @p= CHARINDEX(' ',@S)

While @p > 0
Begin
	Print 'There is a space at position ' + cast(@p as varchar(10))
	Select @p= CHARINDEX(' ',@S,@p+1)
End

Open in new window

fn-split.sql
0
 
Anthony PerkinsCommented:
You can use the CHARINDEX() function repeatedly.  But I am not sure that alone is going to help much in your quest to split unformatted City State ZIP values.
0
 
Anthony PerkinsCommented:
But I see you have already been given this same answer here:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_26013136.html
0
 
VBdotnet2005Author Commented:
How would you do it repeatedly? Charindex(' ',mystring) This would just return the psition of the first ' '. How would you find out the second ' '?
0
 
Anthony PerkinsCommented:
I posted my solution to your unformatted City State ZIP in your other thread (and yes I realize you cannot read code when using EE Mobile):
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_25986403.html

See there for a good example how to do it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.