First letter in string

Posted By: Grat

First letter in string - 05/05/20 14:20

Hi,

sorry for the beginner question, but I cannot find how this make

I'm a need first letter from string I traing find answ. but no work:

Code
		char cFirst = "3CCC3";
		if (cFirst[1] == "C") printf("AAAA");
		if (cFirst[0] == "3") printf("33333");  

have this error:
Quote

Error in 'line 292:
subscript requires array or pointer type
< if (cFirst[1] == "C") printf("AAAA"); >.



Code
		string cFirst = "3CCC3";
		if (cFirst[1] == "C") printf("AAAA");
		if (cFirst[0] == "3") printf("33333");  

this error
Quote

Syntax error: Wrong type EQ:LONG:ARRAY:LONG
< if (cFirst[1] == "C") printf("AAAA"); >


how to test the first letter in the string?

Thank's Milan
Posted By: AndrewAMD

Re: First letter in string - 05/05/20 14:38

A char has single quotes ('), whereas a string has double quotes ("). See the manual:
https://zorro-project.com/manual/en/aarray.htm

Try this:
Code
string cFirst = "3CCC3";
if (cFirst[1] == 'C') printf("AAAA");
if (cFirst[0] == '3') printf("33333");  
Posted By: Grat

Re: First letter in string - 05/05/20 15:04

Thank's this working, I read this page many times, but not see...

laugh
© 2024 lite-C Forums