Doesn't index search for the first occurrence of a particular character
in the string? I think what he's looking for is just the left-most
character everytime, regardless of what it is, which could be done like
this (if you want the rest of the string to go into another variable):

char firstchar;

if ( argument[0] != '\0' )
{
    firstchar = argument[0];
    argument++;
}

that would first check to see if the user didn't enter an argument, and
if they did, assign the first letter (or number) of that argument to
'firstchar', and then increment the space pointed to by argument so that
if argument == 5678, firstchar would = 5, and argument would then =
678... if you want to use this only for numbers, you can simply add a
check for !is_number(argument) before you split off the values, and spit
out an error message if the entire string isn't a number (i.e. 5678a)...

Richard Lindsey 

-----Original Message-----
From: Jason Gauthier [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 12, 2004 11:12 AM
To: Tristan M; [email protected]
Subject: RE: isolating 1 character from a string

You can do this with index().

 

> -----Original Message-----
> From: Tristan M [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, May 12, 2004 12:02 PM
> To: [email protected]
> Subject: isolating 1 character from a string
> 
> Hey, first off thanks for all the help recently, you guys 
> have solved all my problems ive given you so far:) but heres 
> a new one,
> 
> what id like to do is make the code isolate one character 
> from the left, like visual basic's left().
> 
> this is what i want:
> 
> i have a value, say 5678
> i want to return only the 5 to one string and the 678 to another
> 
> is there any way to do this? ive been searching all over the 
> net with no luck
> 
> _________________________________________________________________
> http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&;
> DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
> 
> 
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
> 

-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to