i want to print in notification body like today is jane's birthday
for that i am using logic like below
notification.alertBody = [NSString stringWithFormat:#"Today is %#'s Birthday", [_combinedNameArray objectAtIndex:i]];
but in notification it only shows the name which is jane and not showing Today is birthday
plz tell me what i am doing wrong ?
thank you
Try:
notification.alertBody = [NSString stringWithFormat:#"Today is %#\'s Birthday", [_combinedNameArray objectAtIndex:i]];
(' character needs an escape character)
Related
i want to replace the value of placemark.name with the string MyPostition in a textfield station but this lines of code doesn't work any suggestions please
_station.text = [NSString stringWithFormat:#"%#",placemark.name];
_station.text=[NSString stringWithFormat:#"%#",#"MyPosition"];
If MyPosition is a variable from which you want to set the value then please remove the " from this variable as follows:
_station.text=[NSString stringWithFormat:#"%#",MyPosition];
Update as understood by your requirement:
_station.text = [NSString stringWithFormat:#"%#",placemark.locality];
Please try this code. Its may be useful to you
NSString *str = #"This is a MyPosition";
str = [str stringByReplacingOccurrencesOfString:#"MyPosition"
withString:#"duck"];
Use this format:
_station.text = [NSString stringWithFormat:#"%#",placemark.locality];
I have a textView, in that I am entering the data and I pressed on the enter it is going to next line and I entered some other data and I saved it.
The result I am getting is :
And it is stored in services like :
{"PersonID":9416,"PeriodID":59130,"Notes":"tyyyttyt
ttrtrtrt
ttttrtrtr","PeriodDate":"2015-05-08T10:50:00"}
But my requirement is that the string should be stored as :
tyyyyttyt ttrttrt ttttrtrtr
I searched in google but I didn't get answer for this.
Can any one please help me to sort out this problem ?
I am very new to Objective C topics.
To remove new line from your string use following code:
myString = [myString stringByReplacingOccurrencesOfString:#"\n" withString:#" "];
where myString is the text you fetch from your UITextView.
Hope this helps!
Separate your string in components separated by any new line character, then join them again to a new string, separating them with a space:
NSString *cleanString = [[myTextField.text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:#" "];
Try it. Replace Double Space with Single space.
for (int i=0; i<[self.textView.text length]; i++)
{
self.textView.text=[self.textView.text stringByReplacingOccurrencesOfString:#" " withString:#" "];
}
For example if i had a string like
NSString *myString = #"A B C D E F G";
and I want to remove the spaces, and get a string out like "ABCDEFG".
I could use
NSString *stringWithoutSpaces = [myString stringByReplacingOccurrencesOfString:#" " withString:#""];
However, for my application I am loading in phone numbers from the address book
and the numbers often have a different formatting layout.
I'm wondering if I have a phone number stored in a string like
+1-(937)673-3451 how would I go about removing only the first "1" the "+" the "-" and the "(" ")".
Overall, I would like to know if it is possible to remove the first "1" without removing the last one in the string?
There are a lot of ways to do this. Here's one:
NSString *phoneNumber = #"+1-(937)673-3451";
NSCharacterSet *removalCharacterSet = [NSCharacterSet characterSetWithCharactersInString:#"+()-"];
NSArray *components = [phoneNumber componentsSeparatedByCharactersInSet:removalCharacterSet];
NSString *simplifiedPhoneNumber = [components componentsJoinedByString:#""];
NSRange firstCharacterRange = NSMakeRange(0, 1);
if ([[simplifiedPhoneNumber substringWithRange:firstCharacterRange] isEqualToString:#"1"]) {
simplifiedPhoneNumber = [simplifiedPhoneNumber stringByReplacingCharactersInRange:firstCharacterRange withString:#""];
}
NSLog(#"Full phone number: %#", phoneNumber);
NSLog(#"Simplified phone number: %#", simplifiedPhoneNumber);
But really you want to use a library that knows what a phone number is supposed to look like, like libPhoneNumber.
Ok so I am looking for a piece of code that will take text out of label. Before I tell you , I looked all around internet.
Example
Label's text : Hi I am asking for help.
Ok so what I want the program to do is when I hit a button to remove part of the text like this.
From : Hi I am asking for help to Hi I asking for help
deleting the word 'am'.
Don't tell me to do any manual changing like, label.text = #"Hi I asking for help".
Because the value I am trying to change is static and it is an RSS Reader.
Summary :
I want to remove particular text from label, example taking a word out from the middle of the label and re-displaying the new value.
NSString *myString = #"Hi I am asking for help.";
NSString *updated = [myString stringByReplacingOccurrencesOfString:#" am" withString:#""];
NSLog(#"%#",updated);
output will be:- Hi I asking for help.
try this :
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target
withString:(NSString *)replacement
...to get a new string with a substring replaced (See NSString documentation for others)
Example:
NSString *str = #"Hi I am asking for help.";
str = [str stringByReplacingOccurrencesOfString:#"am"
withString:#""];
this seems like it is probably dead simple to somebody but I'm stuck.
I have this little app that picks a random thing from an array of things and then displays it to the user in the form of a question.
NSLog(#"How about %#?", theThing);
// How About...
self.theThingLabel.text = theThing;
//How do I add a question mark to the end of that string
in the code above the NSLog string works just like I want the label to work. I take care of the "how about" part as a string above the displayed result, but I can't figure out how to add that question mark .. something like theThing+"?"
I tried a bunch of stuff but instead of getting lucky I got warned by xcode over and over.
Try this
self.theThingLabel.text = [theThing stringByAppendingString:#" ?"];
self.theThingLabel.text = [NSString stringWithFormat:#"How about %#?",theThing];
This is very easy
Use this :
self.theThingLabel.text = [NSString stringWithFormat:#"How about %# ?", theThing];
theThing = [NSString stringWithFormat:#"How about %#?",theThing];
NSLog(#"%#", theThing);
then
self.theThingLabel.text = theThing;
Hope it helps..
NSString *what= #"What";
NSString *finalString = [NSString stringWithFormat:#"How about %# ..?", what];
NSLog(#"%#", finalString);
Hope that helps