NSString to NSData conversion [duplicate] - ios

This question already has an answer here:
Converting hex string to hex data
(1 answer)
Closed 9 years ago.
I am having following NSString:
8270be11a217f1420863d76ea7d24820
and i want to convert in following format:
NSData : <8270be11 a217f142 0863d76e a7d24820>
Please help!
Thanks

Try to do this..
NSString* str = #"teststring";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];

Related

Getting XML values [duplicate]

This question already has answers here:
Parsing XML file with NSXMLParser - getting values
(4 answers)
Closed 7 years ago.
I have an xml which i want to parse it , i succesed to do this but i have a question about the structure of this xml .
<BIBLEBOOK bnumber="1" bname="Genesis" bsname="Gen">
<CHAPTER cnumber="1">
<VERS vnumber="1">At the first God made the heaven and the earth.</VERS>
<VERS vnumber="2">And the earth was waste and without form; and it was dark on the face of the deep: and the Spirit of God was moving on the face of the waters.</VERS>
How can i get the value for bname ?
This is how i parse the xml:
NSString *xmlString = [[NSBundle mainBundle] pathForResource:#"basic_english" ofType:#"xml"];
NSData *xmlData = [NSData dataWithContentsOfFile:xmlString];
NSString* dataStr = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
NSDictionary *xmlDoc = [NSDictionary dictionaryWithXMLString:dataStr];
Try this. Hope it will help you.
NSString *bname = [xmlDoc valueForKey:#"_bname"];

How to remove characters from an NSString and replace with spaces? [duplicate]

This question already has answers here:
String replacement in Objective-C
(6 answers)
Closed 8 years ago.
I have a NSString:
NSString *string1 = #"http://example.com/this-is-an-example-post"
By removing a range of characteres I have substringed it to:
NSString *string2 = #"this-is-an-example-post"
But I am struggling to get it into the form of:
NSString *string3 = #"this is an example post"
Any help? Much appreciated.
For example this way
string3 = [string2 stringByReplacingOccurrencesOfString:#"-" withString:#" "];

How to convert NSString to NSMutableString in Objective-C? [duplicate]

This question already has answers here:
How to initialize NSString to NSMutableString?
(4 answers)
Closed 8 years ago.
Is there any way to convert an NSString to NSMutableString in Objective-C?
NSString *string = #"A string.";
NSMutableString *mutableString = [string mutableCopy];

how to convert NSMutableArray into NSString? [duplicate]

This question already has answers here:
How to convert elements of NSMutableArray to NSString
(3 answers)
Closed 9 years ago.
I am trying to convert (or copy?) a NSMutableArray into a NSString. I guess my problem is that I don't really understand the structure of a NSString. In my limited knowledge, a string could look like this: in iphone
Try this code:-
NSString *string = [array componentsJoinedByString:#","];
take the NSMutableString and append every array string into your string
like
string = [string appendString:[NSString stringWithFormat:"%#", [array objectAtIndex:i]]];

How to initialize NSString as text with double quotes [duplicate]

This question already has answers here:
Is it possible to include a quotation mark as part of an nsstring?
(7 answers)
Closed 8 years ago.
i want to initialize NSString is as "hai" with double qoutes..is it possible? any help please?
but NSString *str = #"hai"; i want to convert it as "hai" without direct initialization?any help pls?
If you want to convert an existing string please use this:
NSString *newString = [NSString stringWithFormat:#"\"%#\"",str];
NSString* foo = #"\"hai\"";

Resources