NSString convert to NSArray based on text or special Characters - nsstring

All,
I have requirement of getting a Array from NSString for Example I have String
NSString* aStr = #""This is test" Test "Test This"";
Now In Array i need in below format
"This is Test",
Test,
"Test This"
How can we do this

Related

HTML file contents to Email Body in Progress 4gl

I have created a .html file from a Progress program which contains a table of rows and columns.
I would like to add the contents of the HTML file to an email body that I am sending with the "febooti" email utility on Windows.
How can I send this HTML file from my Progress program using "febooti"?
The febooti.com website says that the tool supports HTML in the body of the email:
https://www.febooti.com/products/command-line-email/commands/htmlfile/
There are a lot of options but a simple 4gl test example might look something like this:
define variable smtpServer as character no-undo.
define variable emailFrom as character no-undo.
define variable emailTo as character no-undo.
define variable emailSubject as character no-undo.
define variable altText as character no-undo.
define variable htmlFileName as character no-undo.
define variable htmlContent as character no-undo.
assign
smtpServer = "smtp.server.com"
emailFrom = "varun#email.com"
emailTo = "someone#email.com"
emailSubject = "Test email!"
altText = "Sorry, your email app cannot display HTML"
htmlFileName = "test.html"
.
/* this is obviously just an example, according to your question you
* have already created the HTML and don't actually need to do this
*/
htmlContent = "<table> <tr><td>abc</td></tr> <tr><td>...</td></tr> <tr><td>xyz</td></tr> </table>".
output to value( htmlFileName ).
put unformatted htmlFile skip.
output close.
/* end of stub html file creation - use your real code */
/* this shells out and sends the email using whatever
* is in htmlFileName as the content
*/
os-command value( substitute( "febootimail -SERVER &1 -FROM &2 -TO &3 -SUBJECT &4 -HTMLFILE &5 -TEXT &6", smtpServer, emailFrom, emailTo, emailSubject, htmlFileName, altText )).

How do I remove all page formatting from NSString

I have an NSMutableString* (theBigString) that contains text loaded from an online file. I am writing theBigString to a local file on the iPad and then emailing it as an attachment.
[theBigString appendString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
Despite my best efforts using the following lines of code, when I open the email attachment there still exists multiple lines of text instead of one long line of text which is what I expected (and need for my app to work).
[theBigString stringByReplacingOccurrencesOfString:#"\\s+" withString:#" "];
[theBigString stringByReplacingOccurrencesOfString:#"\n" withString:#" "];
[theBigString stringByReplacingOccurrencesOfString:#"\r" withString:#" "];
[theBigString stringByReplacingOccurrencesOfString:#"\r\n" withString:#" "];
If I open the text file and view the formatting it still shows a couple of new paragraph symbols.
Is there another newline type character besides "\n" or "\r" that I am not stripping with the above code?
NSCharacterSet defines [NSCharacterSet newLineCharacterSet] as (U+000A–U+000D, U+0085)
If you don't care too much about efficiency, you could also just separate the string into an array at the newline character locations and combine it again with empty strings.
NSArray* stringComponents = [theBigString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
theBigString = [stringComponents componentsJoinedByString:#""];

stringByAddingPercentEscapesUsingEncoding adds unexpected characters?

I'm having a hard time getting my NSURL to work, when I create the final string before converting to URL it adds unwanted character to the end of the string, why is this happening and how can I fix it?
Here is my code:
NSString *remotepathstring = [[NSString alloc] init];
remotepathstring=newdata.remotepath;
NSLog(#"remotepathstring = %#",remotepathstring);
NSString *remotepathstringwithescapes = [remotepathstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"remotepathstring = %#",remotepathstringwithescapes);
remotepathURL =[NSURL URLWithString:remotepathstringwithescapes];
NSLog(#"RemotePathUrl=%#",remotepathURL);
Log outputs as follows:
"remotepathstring = http://nalahandthepinktiger.com/wp-content/uploads/nalah-sheet-5.pdf‎"
"remotepathstring = http://nalahandthepinktiger.com/wp-content/uploads/nalah-sheet-5.pdf%E2%80%8E"
"RemotePathUrl=http://nalahandthepinktiger.com/wp-content/uploads/nalah-sheet-5.pdf%E2%80%8E"
The sequence %E2%80%8E is a Unicode LEFT-TO-RIGHT MARK. This is present in your original remotepathstring, but invisible when printed out via NSLog.
The question becomes: how does newdata.remotepath get populated in the first place? Somewhere along the line it sounds like you need to perform some extra cleanup of input strings to strip out such a character.
Unrelated to the core question, it would seem you're a newcomer to Objective-C. This code is redundant and wasteful:
NSString *remotepathstring = [[NSString alloc] init];
remotepathstring=newdata.remotepath;
You create a string, only to immediately throw it away and replace it with another. If you're not using ARC, this has the additional problem of leaking! Instead do:
NSString *remotepathstring = newdata.remotepath;

Xcode how trim a string with special character $

I've a string with this kind of value /finocchi$FINOCCHamelo
Now I need a new string with only this part of the word FINOCCHamelo
I've try this:
NSString * newString = [item.label stringByReplacingOccurrencesOfString:#"$" withString:#""];
But it's not right becouse change the $ with blank char.
I need to filter the string afther $
How Can I do?
Assuming in all the case you have only one $ in your string and you need the value after $.
NSArray *brokenStrings = [item.label componentsSeparatedByString:#"$"];
NSString *filteredString = [brokenStrings objectAtIndex:1];
There are a lot more ways to do this:
You can opt any one from these methods, or dozen other methods are available in NSString.
– componentsSeparatedByString:
– substringFromIndex:
- rangeOfString:
– stringByTrimmingCharactersInSet:

NSLog NSRange problem

I have a NSSting resultcontent that contains html data which is dynamic and length of html data is always different according to user input.
I could insert my html data in SQLite3 by replacing " from NSString. Now the problem is that SQlite3 doesn't have any inbuilt function to find the position of a particular substring. In SQL you can use CHARINDEX or Patindex for this purpose.
Now I am trying to find the position of this substring "sphinx". I tried NSrange, substringWithRange etc. but I am not getting the exact start and end positions of this substring. How do you show NSRange in console by using NSLog. Here is my code
//find substring "sphinx"
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:#"sphinx"
options:NSRegularExpressionCaseInsensitive
error:&error];
//Get total length of resultcontent (NSString which contains whole html code)
NSInteger lengthTotal=[resultContent length];
NSLog(#"lengthTotal is %i", lengthTotal);
// Get NSRange
NSRange rangeOfSubstring = [regex rangeOfFirstMatchInString:resultContent
options:0
range:NSMakeRange(0, lengthTotal)];
NSString *substringData = [resultContent substringWithRange:rangeOfSubstring];
if (!NSEqualRanges(rangeOfSubstring, NSMakeRange(NSNotFound, 0)))
{
NSString *substringData = [resultContent substringWithRange:rangeOfSubstring];
NSLog(#"substringData is %#", substringData);
[b] // so far it works fine and shows substringData ="sphinx" in Console
//But folowing line doesn't show start and end position of substringData "sphinx"
NSLog([#"range of substring is =%#",[resultContent substringWithRange:rangeOfSubstring] ];[/b]
}
How do I find the exact position of a substring from NSString? I also tried %S in NSLog but no results.
I also have the same NSString resultcontent Data in SQLite table (text datatype). How do you find index of a character or position of a substring in Sqlite without Charindex and patindex function. As html code is dynamic and length varies according to the user input so I need to know the index or position of substring after each user input.

Resources