Solved

Need Help Quickly With Strings

Posted on 2002-07-26
11
144 Views
Last Modified: 2010-05-18
Can anyone show me how I can iterate over each character in a string in VB?
0
Comment
Question by:derekl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7180675

for x = 1 to len(sString)
    sChar = mid(sString,x,1)
next
0
 
LVL 4

Expert Comment

by:gencross
ID: 7180680
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
 

Author Comment

by:derekl
ID: 7180681
I need sChar to be a byte or a long, not a string.  Is this possible?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:gencross
ID: 7180690
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
 
LVL 4

Expert Comment

by:gencross
ID: 7180695
A Byte will work as well, and would probably be the best to use because of memory allocation.
0
 

Author Comment

by:derekl
ID: 7180697
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
 
LVL 4

Accepted Solution

by:
gencross earned 100 total points
ID: 7180711
This should do it...

Dim bChar As Byte

For x = 1 To Len(sstring)
   bChar = Asc(Mid(sstring, x, 1))
Next
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7180728
Dim sString

sString = "Hello World"

For x = 1 To Len(sString)
   Debug.Print Asc(Mid(sString, x, 1))
Next
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7180732
rats... gencross beat me to it....
0
 

Author Comment

by:derekl
ID: 7180742
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7180770
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 13 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question