Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I got coming string from request like:
1 Ghanaian Cedi = 155.15541 Zimbabwe dollar
I want to have 155.15541 in double. How can I do what?
I hear about predicate, can it help here?
If you'd like to parse this string into components separated by the blank spaces use
NSArray *components = [string componentSeparatedBy:#" "];
to get an NSArray in which each index contains each group of characters. In this particular case, your string would return an array containing:
[#"1", #"Ghanaian", #"Cedi", #"=", #"155.15541", #"Zimbabwe", #"dollar"]
If the desired double is always at index 4, you can convert the corresponding string to a double using
double result = [[components objectAtIndex:4] doubleValue];
If the double isn't always at the same index, maybe you could use a regex to identify the double(s).
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to read text from the "Tj/TJ" operator of CGPDFDictionary, but the TJ/Tj operator has the text in (encoded) format for e.g,
Tj = <00><1F><05>. Now i want to get this exact text in NSString i.e NSString should contain "<00><1F><05>".I tried to get the content from TJ/Tj in CGPDFStringRef, but when i am trying to put it in const unsigned char* using CGPDFStringGetBytePtr or in NSString using CGPDFStringCopyTextString i am not getting the desired output. Please suggest me a solution.
Got the answer:
size_t length = CGPDFStringGetLength(string);
NSData *oprData = [NSData dataWithBytes:CGPDFStringGetBytePtr(string) length:length];
NSString *hexString = [[NSString stringWithFormat:#"%#",oprData] uppercaseString];
Here string is the CGPDFStringRef. Finally we get the content of Tj/TJ operator in hexString variable.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am constructing a form and have managed to sort out the input in the form. What I am attempting to do is when an entry is inputed for the postcode it does a check to make sure it follows a pre determined format.
So far I have removed the space, made 2 character sets, one with numerical values and one with just letters. And then done a check on the string length. This is below:-
NSCharacterSet *cset = [NSCharacterSet characterSetWithCharactersInString:#"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
NSCharacterSet *nset = [NSCharacterSet characterSetWithCharactersInString:#"1234567890"];
_QuestionAnswer.text = [_QuestionAnswer.text stringByReplacingOccurrencesOfString:#" " withString:#""]; //removes the space character
if (4 < _QuestionAnswer.text.length < 8) //checks string length between 5 and 7
{
// this is where the format check should be done using cset and nset
}
NB UK post codes must follow any one of the example formats below:-
AA9A 9AA,
A9A 9AA,
A9 9AA,
A99 9AA,
AA9 9AA,
AA99 9AA,
Where 'A' is from cset and '9' is from nset
Thank you in advance.
You can use regular expressions (my is just example):
NSString *laxString = #".+#([A-Za-z0-9]+\\.)";
NSPredicate *postCodeTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", laxString];
return [postCode evaluateWithObject: postCodeTest];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can you convert a string value to decimal code point in xCode? What type of encoding can I use to convert these to the correct representation?
Examples:
string: 9 in decimal code point encoding is 57
string: 1 in decimal code point encoding is 49
string: F in decimal code point encoding is 70
Can you give example to how to do this?
Get the character value instead of the string value. So instead of string #"F" you want character 'F'. NSLog(#"F = %d",'F');
You can do this with a larger string by using the method characterAtIndex:(NSUInteger) and enumerating over the string.
int encVal = (int)[someString characterAtIndex:0];
You can do this:
unichar ch = [someString characterAtIndex:0]; // assume the 1st character
int code = (int)ch;
For the string #"9", ch will be the character '9' and code will be the value 57.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
ex1) a:3:{i:0;s:6:"Apple";i:1;s:4:"Google";}
ex2) a:2:{i:0;s:13:"Area";i:1;s:10:"Place";i:2;s:10:"Location";}
ex3) a:4:{i:0;s:6:"Cool";i:1;s:6:"Nice";i:2;s:6:"Awesome";i:3;s:6:"Wonderful";}
ex4) ...
ex5) ...
this is Answers about our Survey. i received string from server to iPhone. something like that.
a:%d is words count about answer.
i:%d is Index about words. it is increase.
s:%d is length about word.
i don't know what will be word inside double quotation marks. (random)
i understood componentsSeparatedByString.
how to get words inside double quotation marks?
[str stringByReplacingOccurrencesOfString:#"\"" withString:#""];
This will get rid of the quotes. Combine this with my comment and you've got it all figured out.
NSMutableArray *arrSplitString = [NSMutableArray arrayWithArray:[originalString componentsSeperatedByString:#";"]];
for(int i=0; i<[arrSplitString count]; ++i) {
arrSplitString[i] = [arrSplitString[i] stringByReplacingOccurrencesOfString:#"\"" withString:#""];
}
If the ; isn't the char you need to split on, you'll need to change that to the char you need to split on. If you need to split on multiple delimiters, then you'll want to look at the componentsSeparatedByCharactersInSet method.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want check the a string is or not match to american phone number?
(xxx)xxx-xxxx or
xxx-xxx-xxxx
please help me,thank you.
I think the best solution would be using RMPhoneFormat.
As the description says :
RMPhoneFormat *fmt = [[RMPhoneFormat alloc] init];
// Call any number of times
NSString *numberString = // the phone number to validate
BOOL valid = [fmt isPhoneNumberValid:fmt];
Good luck !
Use
https://github.com/rmaddy/RMPhoneFormat
And Check like
For Australia
RMPhoneFormat *formet = [RMPhoneFormat instance];
NSString *MyCode = [formet callingCodeForCountryCode:#"AU"];
NSString *defaultCallingCode = [formet defaultCallingCode];
For India
RMPhoneFormat *formet = [RMPhoneFormat instance];
NSString *MyCode = [formet callingCodeForCountryCode:#"IN"];
NSString *defaultCallingCode = [formet defaultCallingCode];
...
Here MyCode is return code of Country , such like..
For Australia it return - 67
For India it return - 91
This should be easily done with regular expressions. Go through this document http://developer.apple.com/library/mac/documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html and try to make regular expression to check if string matches American phone number pattern.
There are lots of really good tutorials about objective-c regular expressions on the Internet.