Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Stepping through each character in a character string

I'd like to step through the characters in a string and parse out some data.
I want to do something like this

For each Character in myString

Next Character

I get an error that I can only iterate over a collection object or array.
What do I need to do so that I can do this?

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Stepping through each character in a character string

A string isn't a collection, so you can't use For Each...Next


One way:

Dim i As Long
For i = 1 To Len(myString)
Debug.Print Mid(myString, i, 1)
Next i

In article ,
Barb Reinhardt wrote:

I'd like to step through the characters in a string and parse out some data.
I want to do something like this

For each Character in myString

Next Character

I get an error that I can only iterate over a collection object or array.
What do I need to do so that I can do this?

Thanks,
Barb Reinhardt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Stepping through each character in a character string

Sub StepThroughString()

Dim str As String, myString As String

myString = "Test string"

Dim i As Integer

For i = 1 To Len(myString)
str = Mid(myString, i, 1)
Next i

End Sub

HTH, CoRrRan

Barb Reinhardt wrote:
I'd like to step through the characters in a string and parse out some data.
I want to do something like this

For each Character in myString

Next Character

I get an error that I can only iterate over a collection object or array.
What do I need to do so that I can do this?

Thanks,
Barb Reinhardt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Stepping through each character in a character string

I'd like to step through the characters in a string and parse out
some data. I want to do something like this

For each Character in myString

Next Character

I get an error that I can only iterate over a collection object or array.
What do I need to do so that I can do this?


Depending on what you mean by "parse out some data", there MAY be other ways
to do what you want instead of doing a character by character search. Can
you give us an example of a typical string you might want to parse and what
in it you want to remove?

Rick

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting one Character as a String sidfictitious Excel Worksheet Functions 1 February 1st 12 02:03 PM
Excel 2007 - Formatting text in cell (character by character) TomC Excel Discussion (Misc queries) 0 January 29th 10 07:25 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
importing undelimited text file data, character-by-character The Mos$ Excel Programming 4 December 26th 05 11:01 AM
Function to return Character Position of Xth character within a string Andibevan[_2_] Excel Programming 4 June 9th 05 03:24 PM


All times are GMT +1. The time now is 05:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"