View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Harlan Grove[_5_] Harlan Grove[_5_] is offline
external usenet poster
 
Posts: 97
Default counting spaces in a string

"xnman" wrote...
1. Is there a simple way to count the spaces in a long string?


Simplest:

n = Len(s) - Len(Application.WorksheetFunction.Substitute(s, " ", ""))

2. If you have multiple spaces in a string, is there a simple way to
determine what position in the string, number 4 space is?


You could use something like

n = InStr(1, Application.WorksheetFunction.Substitute(s, " ", Chr(127), _
inst), Chr(127))

--
Never attach files.
Snip unnecessary quoted text.
Never multipost (though crossposting is usually OK).
Don't change subject lines because it corrupts Google newsgroup archives.