Separate an NSString into NSArrau using Regular expression - nsstring

I am trying to Separate an NSString into NSArray. I always used 'componentsSeparatedByString' to separate an NSString. But this method only get single separator also without any conditions. I want to separate string from "dot + space", "dot + newline", "dot + empty", "!" and "?". I am sure this could be done with regular expression but don't know how :D. I have never used regular expression before.
Thankyou

You can try the following hope it will work for you
NSString *strTest = #"a.b+c";
NSLog(#"seperated %#", [strTest componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#".+"]]);

Related

When do we use double quotes in R?

So,I am a very beginner in R,I wanted to ask this-
inside read.csv ,we are using "",but while writting summary/mean/sd etc. we don't use "". Why is this the case?
Double quotes " demark strings of characters, text inside code. Code itself is not double-quoted.
The following is valid code
name.of.file <- "C:\\Users\\bernhard\\valued_data.csv"
read.csv(name.of.file)
So you see, there is nothing special about read.csv, it takes the file name either as a string in "s or as a variable containing that string; no " in the latter case.

Add a newline to a string in Scilab

Create a simple string in Scilab containing a newline.
Seems simple enough, but Scilab only seems to interpret escape sequences through printf style functions and msprintf / sprintf splits the string into a vector of strings at the newline!
The only way I can see to achieve this is to actually write a newline out to a file and read it back in again. Surely there is a simpler way to do this!
Ok, found it. The ascii function will do the job, a newline can be added via its ascii decimal -
str = 'hello' + ascii(10) + 'world'

ActiveXObject("Shell.Application") - how to pass arguments with spaces?

I run exe from my asp.net with JavaScript using ActiveXObject. It runs successfully, except parameters:
function CallEXE() {
var oShell = new ActiveXObject("Shell.Application");
var prog = "C:\\Users\\admin\\Desktop\\myCustom.exe";
oShell.ShellExecute(prog,"customer name fullname","","open","1");
}
Example, I pass that like parameters,[1] customer name,[2] fullname, but after space character, Javascript perceive different parameter.
How can I fix?
ShellExecute takes the 2nd parameter to be a string that represents all the arguments and processes these using normal shell processing rules: spaces and quotes, in particular.
oShell.ShellExecute(prog,"customer name fullname",...)
In this case the 3 parameters that are passed are customer, name, fullname
oShell.ShellExecute(prog,"customer 'a name with spaces' fullname",...)
As corrected/noted by Remy Lebeau - TeamB, double-quotes can be used to defined argument boundaries:
oShell.ShellExecute(prog,'customer "a name with spaces" fullname',...)
In this case the 3 parameters that are passed are customer, a name with spaces, fullname
That is, think of how you would call myCustom.exe from the command-prompt. It's the same thing when using ShellExecute.
Happy coding.
Try escaping your spaces with a backslash. The cmd.exe cd command does this, maybe you'll get lucky and it'll work here as well...
oShell.ShellExecute(prog,"customer a\ name\ with\ spaces fullname", ...)

is there any way to pass string contains '+' via the Querystring

I need to pass '+' via the QueryString.
some special character can be passed by using 'Encode' .. but '+'
I know the one solution, If I replace '+' with other character.
But it's not the perfect solution.
[edited]
well I used escape() javascript function to encode.
escape function can't encode + . is the another function to encode on javascript?
Rather than handling on a case by case basis, with Javascript you can encode all data you pass via query string with encodeURIComponent
<script>
var data = ")(#&^$#*&^#!(!*++=";
var encodedData = encodeURIComponent(data);
alert(encodedData);
</script>
Use %2b to pass the + character.
The space character is usually passed as %20.
The same way, the plus sign can be passed as %2B
In ASCII, the hex code for + is 2B, so you should be able to just use %2B instead of +.
http://www.google.com/search?q=c%2B%2B+java

asp.net regular expression not working as expected

I have a textbox and a regular expression validator applied to it. I want to make sure that the only allowed string inputted into the textbox are "Anything Entered" or "Something Else" or "Another String" otherwise I want an error to be displayed.
This is the regular expression I have so far:
ValidationExpression="(^Anything Entered)$|(^Something Else)$ |(^Another String)$"
However when I enter the supposed valid strings the error is displayed. I cant figure out whats wrong with the expression. Any help would be greatly appreciated.
The RegularExpressionValidator automatically adds those ^ and $. Just use
"(Anything Entered|something Else|Another String)"
"^(Anything Entered)|(Something Else)|(Another String)$"
Note the use of ^ and $.
Although, as others have already pointed out, using ^ $ is redundant here.
"(Anything Entered|Something Else|Another String)" is just fine.
(^Anything Entered)$|(^Something Else)$ |(^Another String)$
In regex ^ matches the beginning of the string and $ matches the end of the string.
Your regex is equivalent to (^Anything Entered$)|(^Something Else$ )|(^Another String$). It matches "Anything Entered" or "Another String" but it doesn't match "Something Else" because there can't be a space after the end of the string ($ ).

Resources