How to convert NSString to char? - nsstring

I'm trying to convert an NSString to a single char. When I write [[NSLocale] currentLocale] objectForKey:NSLocaleDecimalSeparator], I get #",". How can I convert this to ','?
Thank you!

unichar character = [myNSString characterAtIndex:0];

Related

Check if date valid using moment and format 'YYYY-MM-DDThh:mm:ss.SSS+ss:ss' does not work

I'm trying to check if a string YYYY-MM-DDThh:mm:ss.SSS+ss:ss
But I always get false.
For example:
const value = '2022-02-16T22:23:53.000+00:00'
moment(value, DATE_FORMAT, true).isValid();
Please advise, am I using the wrong format ?
Date format should have been - YYYY-MM-DDTHH:mm:ss.SSSZ

How to convert Date Time into String value?

I try to Convert String into Date. I get the error such as Cannot implicitly convert type 'System.DateTime' to 'String'.
Aspx code
p.Dob = Convert.ToDateTime(txtDOB.Text);
Can you help me, How solve this error.
If "p.Dob" is string:
p.Dob = Convert.ToDateTime(txtDOB.Text).ToString("dd/MM/yyyy");

stringByAddingPercentEscapesUsingEncoding adds unexpected characters?

I'm having a hard time getting my NSURL to work, when I create the final string before converting to URL it adds unwanted character to the end of the string, why is this happening and how can I fix it?
Here is my code:
NSString *remotepathstring = [[NSString alloc] init];
remotepathstring=newdata.remotepath;
NSLog(#"remotepathstring = %#",remotepathstring);
NSString *remotepathstringwithescapes = [remotepathstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"remotepathstring = %#",remotepathstringwithescapes);
remotepathURL =[NSURL URLWithString:remotepathstringwithescapes];
NSLog(#"RemotePathUrl=%#",remotepathURL);
Log outputs as follows:
"remotepathstring = http://nalahandthepinktiger.com/wp-content/uploads/nalah-sheet-5.pdf‎"
"remotepathstring = http://nalahandthepinktiger.com/wp-content/uploads/nalah-sheet-5.pdf%E2%80%8E"
"RemotePathUrl=http://nalahandthepinktiger.com/wp-content/uploads/nalah-sheet-5.pdf%E2%80%8E"
The sequence %E2%80%8E is a Unicode LEFT-TO-RIGHT MARK. This is present in your original remotepathstring, but invisible when printed out via NSLog.
The question becomes: how does newdata.remotepath get populated in the first place? Somewhere along the line it sounds like you need to perform some extra cleanup of input strings to strip out such a character.
Unrelated to the core question, it would seem you're a newcomer to Objective-C. This code is redundant and wasteful:
NSString *remotepathstring = [[NSString alloc] init];
remotepathstring=newdata.remotepath;
You create a string, only to immediately throw it away and replace it with another. If you're not using ARC, this has the additional problem of leaking! Instead do:
NSString *remotepathstring = newdata.remotepath;

Xcode how trim a string with special character $

I've a string with this kind of value /finocchi$FINOCCHamelo
Now I need a new string with only this part of the word FINOCCHamelo
I've try this:
NSString * newString = [item.label stringByReplacingOccurrencesOfString:#"$" withString:#""];
But it's not right becouse change the $ with blank char.
I need to filter the string afther $
How Can I do?
Assuming in all the case you have only one $ in your string and you need the value after $.
NSArray *brokenStrings = [item.label componentsSeparatedByString:#"$"];
NSString *filteredString = [brokenStrings objectAtIndex:1];
There are a lot more ways to do this:
You can opt any one from these methods, or dozen other methods are available in NSString.
– componentsSeparatedByString:
– substringFromIndex:
- rangeOfString:
– stringByTrimmingCharactersInSet:

How to get string from a long string?

I have a string like this:
NSString *aString =
[NSString stringWithFormat:"********************Documents/image%#.jpg",aNumber];
I want to get "Documents/image%#.jpg" out of the string?
What can I do? I want to use "substringFromIndex" but I don't know the index.
You can use rangeOfString to find the index of "Documents...".
NSString class reference
And then use that with 'substringFromIndex' to get the substring you want.
For example:
[astring substringFromIndex:[aString rangeOfString:#"Documents"].location]
You should add error checking to make sure that the range returned by the 'rangeOfString' method is good.

Resources