Is the first character in a string a letter?

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

There must be an easier way then what I'm doing to determine if the first
character in a string is a valid letter.

My code is getting to big. There must be a better way.

Thanks in advance
 
Frank said:
There must be an easier way then what I'm doing to determine if the first
character in a string is a valid letter.

My code is getting to big. There must be a better way.

Anything wrong with isalpha(s[0]) ?

Brian
 
The only thing wrong with it is that I couldn't find it

thanks

Brian Muth said:
Frank said:
There must be an easier way then what I'm doing to determine if the first
character in a string is a valid letter.

My code is getting to big. There must be a better way.

Anything wrong with isalpha(s[0]) ?

Brian
 
While I was at it I should have asked you about trimming a string of leading
white space.

Is there a easy way?

I've been searching the doc and the internet but can't find anything.

Thanks again


Brian Muth said:
Frank said:
There must be an easier way then what I'm doing to determine if the first
character in a string is a valid letter.

My code is getting to big. There must be a better way.

Anything wrong with isalpha(s[0]) ?

Brian
 
I found something to try


Frank said:
While I was at it I should have asked you about trimming a string of
leading white space.

Is there a easy way?

I've been searching the doc and the internet but can't find anything.

Thanks again


Brian Muth said:
Frank said:
There must be an easier way then what I'm doing to determine if the
first character in a string is a valid letter.

My code is getting to big. There must be a better way.

Anything wrong with isalpha(s[0]) ?

Brian
 
Frank said:
While I was at it I should have asked you about trimming a string of leading
white space.

Is there a easy way?

I've been searching the doc and the internet but can't find anything.

Frank:

If you are using CString then there is TrimLeft().

David Wilkinson
 
I'm doing plain C
Can you see what is wrong with the while statement
ComboBox_GetText(GetDlgItem( hDlg, IDC_N_USERNAME), szTmpStr,
SIZE_OF_USER_NAME);

strcpy_s(szTmpStr2,72,szTmpStr);

strcat_s(szTmpStr2,72, "5"); //Make sure the strip code that follows leaves
something

while (iswspace(*szTmpStr2)) szTmpStr2++; //Error 1 error C2105: '++' needs
l-value


if( !isalpha(szTmpStr2[0])) //check the first character


Thanks for the reply
 
Frank said:
I'm doing plain C
Can you see what is wrong with the while statement
ComboBox_GetText(GetDlgItem( hDlg, IDC_N_USERNAME), szTmpStr,
SIZE_OF_USER_NAME);

strcpy_s(szTmpStr2,72,szTmpStr);

strcat_s(szTmpStr2,72, "5"); //Make sure the strip code that follows
leaves something

while (iswspace(*szTmpStr2)) szTmpStr2++; //Error 1 error C2105: '++'
needs l-value

char *p = szTmpStr2;
while (iswspace(*p)) p++;
 
I'm constantly on it
Knowing the correct thing to search for is the trick to not getting 10
million hits
 
I should have given you one more line of code

ComboBox_GetText(GetDlgItem( hDlg, IDC_N_USERNAME), szTmpStr,
SIZE_OF_USER_NAME);

strcpy_s(szTmpStr2,72,szTmpStr);

strcat_s(szTmpStr2,72, "5"); //Make sure the strip code that follows leaves
something

while (isspace(*szTmpStr2)) szTmpStr2++; //Error 1 error C2105: '++' needs
l-value

if( !isalpha(szTmpStr2[0]))
 
strcpy_s(szTmpStr2,72,szTmpStr);
strcat_s(szTmpStr2,72, "5"); //Make sure the strip code that follows leaves
something
while (isspace(*szTmpStr2)) szTmpStr2++; //Error 1 error C2105: '++' needs
l-value

Make a pointer, then ++ it. For example:

char* pStart = &szTempStr2[0];
while(isSpace(*pStart)) ++pStart;

At the end, pStart is a pointer to some memory (WITHIN szTempStr2)
that has the string minus any leading spaces. Copy that off to another
buffer if you want.

Nathan Mates
 
Thanks
Nathan Mates said:
strcpy_s(szTmpStr2,72,szTmpStr);
strcat_s(szTmpStr2,72, "5"); //Make sure the strip code that follows
leaves
something
while (isspace(*szTmpStr2)) szTmpStr2++; //Error 1 error C2105: '++' needs
l-value

Make a pointer, then ++ it. For example:

char* pStart = &szTempStr2[0];
while(isSpace(*pStart)) ++pStart;

At the end, pStart is a pointer to some memory (WITHIN szTempStr2)
that has the string minus any leading spaces. Copy that off to another
buffer if you want.

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A.
Heinlein
 
Back
Top