Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about String operations 1

Status
Not open for further replies.

powahusr

Technical User
Joined
Jan 22, 2001
Messages
240
Location
US
How can you return the value of a character at a specified position in a string?

For instance, say I have the following string:

"Baseball, Football, Hockey and Basketball"

If I wanted to return the value of the character at positions 5 and 23 ("b", "c"), how would I be able to do it?

I tried using the "Find" function, but that only returns the first occurrence of a character. Not quite, what I am looking for. I also tried incorporating a loop structure and modified the Find function, but it seems as though the "Find" function is limited.

Any Suggestions?

Thanks in Advance!!!
 
Hmmmm... seems like you're asking two different questions.

You would use
Code:
Find()
in the opposite way of what you describe. The
Code:
Find()
function takes the base string, and finds the position of a given substring.

ie- in your example, if I said:
Code:
Find("Baseball, Football, Hockey and Basketball","b")
it would return "5" (since the first B is capitalized, and we're using Find instead of FindNoCase).

But from your initial question, it sounds like you actually want to go the other way... find the character that's at position 5.

You could do this with the
Code:
Mid()
function.

Code:
Mid("Baseball, Football, Hockey and Basketball",5,1)
would return "b".


Is that what you're after?




-Carl
 
Yes, your answer was the approach I was looking to take to solving the problem. Thank You
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top