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!
将字符串分隔为由任何换行符分隔的组件,然后将它们再次连接到新字符串,并用空格分隔:
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:@" "];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.