|Aug 3, 2012, 08:33 PM||#1|
Replace parts of text strings
In my app I have a plist of many quotes. These quotes are loaded into a UILabel, and has the option to share with Twitter. Some quotes are quite long, and I know I could easily cut all characters past the first 140, but I would like to include the name attributed to the quote at the end. Each quote is setup like this:
"I just said something famous." - Me
If the UILabel.text length is over 140 I would like to get the length, and subtract 140 from it, so I know how many characters must be removed. I have this part all setup in my code already. What I'm not for sure how to do is this:
If the quote has 200 characters, find " -
Then, remove the 63 characters immediately in front of " -
Replace those 63 characters with ...
This way a quote that looks like what I put above, if too long, would end up looking like:
"I just said someth..." - Me
I realize that there will be many occasions that it cuts a word off right in the middle, but I am willing to live with that. Any suggestions for removing a certain number of characters before the " - in the quote?
|Aug 4, 2012, 01:30 AM||#2|
If you are certain that the symbol - does not show up elsewhere in any of the quotes you could simply do this in a two step process.
First separate the original string by using the componentsSeparatedByString: method. You should then have an array with two strings. The first one consisting of the actual quote and the second of the name. Then you can use the part of your quote that shortens the quote on the first string and output them however you like.
Personally I would rework your method for shortening the quote as well. Rather than simply counting the letters you can separate the string by white space @" " thus ending up with an array of all the single words. Then use a mutable string and while loop structure to add each single word (+ a white space) from the array of words. Simply run the loop until the length of the mutable string + the next word in the array are larger than the 140 characters.
Last edited by NickFalk; Aug 4, 2012 at 03:16 AM. Reason: typo
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|What parts will I need to replace my broken iPhone screen?||falloutmike||iPhone Tips, Help and Troubleshooting||3||Jul 25, 2013 03:41 PM|
|Is there a 3rd party imessage/text app to replace apple's?||Italianblend||iPhone||1||Mar 20, 2013 08:24 AM|
|Find and Replace Text in PDF Files||jisaac||Mac Applications and Mac App Store||3||Jan 11, 2013 08:35 PM|
|Corrosion damage on Logicboard... Replace or do something with the parts?||daftpuff||MacBook Pro||2||Sep 13, 2012 04:55 PM|
|Can Apple replace my craigslist iphone which is "missing parts"?||lilmopho||iPhone||25||Aug 14, 2012 02:34 PM|
All times are GMT -5. The time now is 03:19 AM.