Find space in string

How can I find specific  position of each space? Sample: This is a test only.
VBdotnet2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
BanthorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.