Find space in string

How can I find specific  position of each space? Sample: This is a test only.
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
	Print 'There is a space at position ' + cast(@p as varchar(10))
	Select @p= CHARINDEX(' ',@S,@p+1)

Open in new window

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.
Anthony PerkinsCommented:
But I see you have already been given this same answer here:
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 ' '?
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):

See there for a good example how to do it.
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.