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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

left$(variable$)

Status
Not open for further replies.

The

Programmer
Jul 30, 2001
92
CA
Hey,
Ok, I'm not a COMPLETE newbie, but I'm not a guru, either. What I want to do is have a for-next loop, and every time the loop goes around, it takes the "x"th letter from a string variable. For example, if the string variable was "Hello", the loop would go around 5 times, and msg$(1)
would be "H", msg$(2) would be "e", msg$(3) would be "l" and so on. I tried using the left$("hello"), but for msg$(2) it gives me "He" instead of just "e". Does anyone know the command I would use to get a single letter, instead of a letter and all the letters before it? Thanks.
 
To get i-th letter:
mid$("Hello",i,1)
 
This...

Code:
A$ = "hello"
REDIM MSG$(LEN(A$))
FOR I = 1 TO LEN(A$)
  MSG$(I) = MID$(A$,I,1)
NEXT

...Should get you what you want...

Also...

When:
A$ = "Hello"
...
LEN(A$) = 5
LEFT$(A$,2) = "He"
LEFT$(A$,LEN(A$)-2) = "Hel"
RIGHT$(A$,2) = "lo"
RIGHT$(A$,LEN(A$)-2) = "llo"
MID$(A$,2,3) = "ell"
INSTR(A$,"e") = 2
INSTR(A$,"z") = 0

When:
A$ = " Hello "
...
LTRIM$(A$) = "Hello "
RTRIM$(A$) = " Hello"
LTRIM$(RTRIM$(A$)) = "Hello"

Good Luck... ;-)

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top