Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I have a string "1.2345677".
I want only "1.23" for further use.
how to remove other string.
Any Help
Thanks.
Like so:
NSString *origString = #"1.2345677";
NSString *subString = [origString substringToIndex:3];
NSString *mainstr = #"1.2345677";
float conver = [mainstr floatValue];
NSString *floatedstr =[NSString stringWithFormat:#"%.2f",conver];
You can also do it with
NSNumberFormatter *format = [[NSNumberFormatter alloc] init];
[format setFormat:#"0.##"];
NSLog(#"%#", [format stringFromNumber:[NSNumber numberWithFloat:25.342]]);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
The following code is not converting a string into a date as I would hope.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSString *starttimestr = feedElement[#"starttime"];
NSLog(#"starttimestr%#",starttimestr);//this returns 'starttimestr NSString * #"2015-10-20 14:30:00" 0x1765ddc0'
NSDate *starttime = [dateFormatter dateFromString:starttimestr];
NSLog(#"starttime%#",starttime);//this returns nil
Can anyone see what is going wrong?
Your dateFormat has to match the format of the string for it to work. So you can get rid of the 'T' and the time zone stuff since none of that is actually in the string.
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 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).
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.