Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Need Help Quickly With Strings

Can anyone show me how I can iterate over each character in a string in VB?
0
derekl
Asked:
derekl
  • 5
  • 3
  • 2
  • +1
1 Solution
 
gencrossCommented:

for x = 1 to len(sString)
    sChar = mid(sString,x,1)
next
0
 
gencrossCommented:
This code will return every charecter of a string, one at a time in sChar variable.

Let me know if I am off base.
0
 
dereklAuthor Commented:
I need sChar to be a byte or a long, not a string.  Is this possible?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
gencrossCommented:
It is not a problem to change sChar to a long, as long as the data in the string is numeric.  However, if the data is numeric and you are looking at one charecter at a time it would make more sense to use an integer.  It will take up less memory.
0
 
gencrossCommented:
A Byte will work as well, and would probably be the best to use because of memory allocation.
0
 
dereklAuthor Commented:
The data is definitely non numeric.  What I really need is the ascii value of every character in the string be it a number or letter.
0
 
gencrossCommented:
This should do it...

Dim bChar As Byte

For x = 1 To Len(sstring)
   bChar = Asc(Mid(sstring, x, 1))
Next
0
 
mdouganCommented:
Dim sString

sString = "Hello World"

For x = 1 To Len(sString)
   Debug.Print Asc(Mid(sString, x, 1))
Next
0
 
mdouganCommented:
rats... gencross beat me to it....
0
 
dereklAuthor Commented:
Thanks, you saved my life.  

You know as easy as VB makes working with COM components and stuff it makes this kind of problem equally hard.  At least for a recent convert from C++.
0
 
Anthony PerkinsCommented:
Any chance we can get you to close out some of your open questions:

Questions Asked 57
Last 10 Grades Given A B B A A A A A B A  
Question Grading Record 48 Answers Graded / 48 Answers Received

Thanks,
Anthony
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.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now