problem in string by replace occurance - iphone

i am getting the problem when i get the result from the xml api web service i use
NSString *productName = [[paramName stringByReplacingOccurrencesOfString:#"\"" withString:#""] mutableCopy];
paramName is the argument of the function, but it can't replace the \ string which are on database
please help me out... thanks.
i only want to replace \ to none #"" but its not working now... please help me.. !!
i tried before its working but its not working now .. !! :(

Probably, you meant #"\\", not #"\"". It looks like you're trying to kill quotes, not backslashes.

Related

Intuit.Ipp.Data.Qbo.CustomerQuery query with & in the name

How do you use Intuit.Ipp.Data.Qbo.CustomerQuery to query a name like:
Tom & Jerry's
This case has 2 special characters that are causing the query to fail. One being & and the other being '. I've tried to use Uri.EscapeDataString and it doesn't work. Any advice?
The SDK does not encode the ampersand correctly, so you will need to use DevDefined and deserialize the response with the SDK. Code sample: https://gist.github.com/IntuitDeveloperRelations/6024616
you would need to xml encode the string.
thanks
Jarred

iPhone app: emoji unicode

I have a Json return that has a string that sometimes inludes something like \Uf604 in the array (IE memo = "\Uf604";). I need to convert it to \U0001F604 if possible.
I tried to do something like stringByReplacingOccurrencesOfString but at that point when its in a string and it's been converted to ÔòÑ which I think it needs to be üòÑ to be displayed as a emoticon. I also tried
[str stringByReplacingOccurrencesOfString:#"Ô" withString:#"ü"];
But that didn't change anything. It still gets returned as ÔòÑ.
Any help would be appreciated!
I believe str = [str stringByReplacingOccurrencesOfString:#"Ô" withString:#"ü"]; is what you are trying to do.
stringByReplacingOccurrencesOfString:withString: doesn't change the string you are calling on but returns a new string with replaced characters.

How to add a character at the beginning of an existing string in objective-c?

How do I add a single character such as a '$' or a '+' at the beginning of an existing string?
I tried using the appendingString method but that adds the $ or + at the end of the string.
I know I can always save the $ or + in a new string and then append the other string, but I just want to know if there is a better way to do it.
Thank you.
This is actually very simple:
[#"+" stringByAppendingString:existingString];
This should definitely work for you :) And the + will be at the beginning.
Strings aren't mutable. You're creating a new string when you use stringByAppendingString: In order to prepend, you would have to make a mutable version of your existing string and then use insertString:atIndex: like so:
[[NSMutableString stringWithString:myString] insertString:#"$" atIndex:0];
Why there isn't a stringByPrependingString:, I don't know.
The best solution is the one you've already mentioned:
[#"$" stringByAppendingString:myString];
As long as the string is mutable, i.e. it is an NSMutableString you can use.
[str insertString:#"$" atIndex:0];
Have a read of the docs here, https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsmutablestring_Class/Reference/Reference.html

iphone sqlite quotes problem

I have a problem with a following sqlite query:
sql = [NSString stringWithFormat:#"Insert into table_name(height)values('%#')",heightarray];
I am getting heightarray from XML, the value of heightarray is:
array = ( "5'0\"-5'3\"",
"5'4\"-5'8\"",
"5'9\"-6'0\"" )
The \" is added implicitly for some reason, I don't know why?
It is causing problem. please help.
try to use
sql = [NSString stringWithFormat:#"Insert into table_name(height)values(?)"];
and then use
sqlite3_bind_text
If you're using sqlite try this wrapper it helps a lot
https://github.com/ccgus/fmdb
There are detailed examples how to use it.

Regex with #-sign not working

I am using RegexKitLite in an iPhone project and want to use regex to find words that start with the #-sign. For instance, "#home #chores", when searched, would return both words.
The regex string I am using is "(?m-s:#.*\\s*)". When I use this, though, I get a crash. When I use the same thing, but with a # instead of #, it works just fine: "(?m-s:#.*\\s*)". WTF?
I would much appreciate it if someone with a better understanding of regular expressions could help me on this. The tutorials I have seen so far have been near incomprehensible to me.
I did a modification of Manu's idea, just switching the location of the # in the regex.
/(#\b\w+)/
I tested it on a string with '#foo #bar #baz #lol' and it seemed to do what you're looking for in matching on the words and capturing them with the parens.
Have you tried something like that:
NSString *search = #"This is my #home string with #some tokens to be #found";
NSString *regex = #"\\b#(\\w+)";
NSArray *matches = NULL;
matches = [search componentsMatchedByRegex:regex];
// now matches should have { #"home", #"some", #"found" } values
I haven't tested that but should work.
This may sound too simple, but have you tried changing # to \# or \\#
Why not simply use /\b#\w+/?