Class to parse an input string and calculate its value.
The string can contain numbers, .
, (
, )
, /
, *
, -
, and +
symbols.
It also checks, that if the user adds a number, .
, (
, )
, /
, *
, -
, or +
to a string, would that string be a valid string to calculate or not.
+(BOOL)usingThis:(NSString )string addThis:(NSString )newString;
+(BOOL)usingThis:(NSString )string addThis:(NSString )newString here:(NSRange)range;
+(NSString )stringFrom:(NSString )string withThis:(NSString )newString;
+(NSString )stringFrom:(NSString )string withThis:(NSString )newString here:(NSRange)range;
+(NSNumber )solveString:(NSString )string;
Check if adding a new string, at the end, to a previous string would create a valid expression.
+(BOOL)usingThis:(NSString )string addThis:(NSString )newString;
Parameters
string
Base string where you want to add.
newString
String to check if adding it would create a correct expression.
Return Value
YES
if adding the newString to string would create a valid expression, otherwise NO
Discussion
This assumes the newString would be added at the end of string.
Check if adding a new string, at the specified location, to a previous string would create a valid expression.
+(BOOL)usingThis:(NSString )string addThis:(NSString )newString here:(NSRange)range;
Parameters
string
Base string where you want to add something.
newString
String to check if adding it would create a correct expression.
range
Range where string would be added.
Return Value
YES
if adding the newString to string would create a valid expression, otherwise NO
+(NSString )stringFrom:(NSString )string withThis:(NSString *)newString; Add a new string to the end of a previous string.
Parameters
string
Base string where you want to add.
newString
String to check if adding it would create a correct expression.
Return Value
A string with containing the previous string with the new string appended.
Add a new string at the specified location to a previous string.
+(NSString )stringFrom:(NSString )string withThis:(NSString *)newString here:(NSRange)range;
Parameters
string
Base string where you want to add something.
newString
String to check if adding it would create a correct expression.
range
Range where string would be added.
Return Value
A string with containing the previous string with the new string in the specified location.
Solve an mathematical expression.
+(NSNumber )solveString:(NSString )string;
Parameters
string
String containing the mathematical expression.
Return Value
A number with the result of the mathematical expression, nil if it is not a well formed expression.