Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Check string[i] for content
Check string[i] for content [message #34460] Wed, 23 November 2011 13:51 Go to next message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
Hello,

i try to make something like a parser....

void curve::term_op1(String &term, String &newterm, int &pos)
{
	String justOne = term.Mid(pos,1);
	
	if (justOne.IsEqual("+"))
	{
		newterm << " + ";
		pos++;
	} else if (justOne.IsEqual("-"))
	{
		newterm << " - ";
		pos++;
	} else
	{
		if (IsDigit(justOne))
		{ /* should trigger if it is a number 0-9) */
			newterm << " INT (" << justOne << ") ";
			pos++;
		} else
		{
			newterm << " Something else (" << justOne << ") ";
			pos++;	
		}
	}
}


Of course the "IsDigit" does not work.... can someone tell me how to do this... maybe without a String with 1 character in it (i think its really bad to do it this way?)


Thanks!

Best regards,
Wolfgang

[Updated on: Wed, 23 November 2011 13:52]

Report message to a moderator

Re: Check string[i] for content [message #34461 is a reply to message #34460] Wed, 23 November 2011 14:06 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
If you are doing it this way, why not use character based comparison. A string with length 1 is completely different from a character:

void term_op1(String &term, String &newterm, int &pos)
{
	char justOne = term[pos];
	
	if (justOne == '+')
	{
		newterm << " + ";
		pos++;
	} else if (justOne == '-')
	{
		newterm << " - ";
		pos++;
	} else
	{
		if (IsDigit(justOne))
		{ /* should trigger if it is a number 0-9) */
			newterm << " INT (" << justOne << ") ";
			pos++;
		} else
		{
			newterm << " Something else (" << justOne << ") ";
			pos++;	
		}
	}
}


Also, check out CParser class. It is very powerful.

PS: I did not check you code, only made it compile Smile.
Re: Check string[i] for content [message #34462 is a reply to message #34461] Wed, 23 November 2011 14:10 Go to previous message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
thank you for your help.... its not really a project with the aim to make things easy, its just for me to improve my skills.

At least my first step is to check a mathematic term for validity..

Thanks for the hint with the char, I don't know why but I looked for something like IsEqual for char ---> stupid Very Happy
Asked myself how to compare a char to something..
Previous Topic: What Type to give a Layout as parameter?
Next Topic: How do I get back to the .lay visual editor after a run
Goto Forum:
  


Current Time: Fri Apr 19 11:53:19 CEST 2024

Total time taken to generate the page: 0.02393 seconds