Groups | Blog | Home
all groups > visual c > january 2007 >

visual c : Is the first character in a string a letter?


Brian Muth
1/31/2007 8:56:17 AM

[quoted text, click to view]

Anything wrong with isalpha(s[0]) ?

Brian

Brian Muth
1/31/2007 9:41:49 AM

[quoted text, click to view]

Couldn't find it? Have you heard of Google by any chance?

http://msdn2.microsoft.com/en-us/library/xt82b8z8(VS.80).aspx

Brian

Brian Muth
1/31/2007 9:45:27 AM

[quoted text, click to view]

char *p = szTmpStr2;
while (iswspace(*p)) p++;


Frank
1/31/2007 11:42:05 AM
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
1/31/2007 12:02:14 PM
The only thing wrong with it is that I couldn't find it

thanks

[quoted text, click to view]

Frank
1/31/2007 12:14:19 PM
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


[quoted text, click to view]

Frank
1/31/2007 12:21:41 PM
I found something to try


[quoted text, click to view]

David Wilkinson
1/31/2007 12:25:27 PM
[quoted text, click to view]

Frank:

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

Frank
1/31/2007 12:40:15 PM
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


[quoted text, click to view]

Frank
1/31/2007 1:43:13 PM
I'm constantly on it
Knowing the correct thing to search for is the trick to not getting 10
million hits

[quoted text, click to view]

Frank
1/31/2007 1:59:27 PM
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]))




[quoted text, click to view]

Frank
1/31/2007 2:27:25 PM
Thanks
[quoted text, click to view]

nathan NO[at]SPAM visi.com
1/31/2007 7:16:47 PM
In article <eH0LxnWRHHA.4276@TK2MSFTNGP02.phx.gbl>,
[quoted text, click to view]

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
AddThis Social Bookmark Button