I'm trying to display to a user 'streamlines'. How would I do this?? I've tried using disp() with " inserted with failure.
How would I go about doing this?
Single quotes need to be escaped by placing a single quote in front of them. Something like this:
username = '''streamlines'''
disp(username)
I think you´re asking how to write the apostrophe, right? if is that you just have to double the apostrophe and it will show up like just one. It would be like: ''streamlines''.
Related
echo 'Text\n' >\*\\'"Text in Here"\'\\*$\?\*\*\*\*\*:)
I want to write that file name but it seems like it's impossible to do with these blackslashes
You are just missing a back slash to escape the last bracket
echo 'Text\n' >\*\\'"Text in Here"\'\\*$\?\*\*\*\*\*:\)
EDIT: I didn't see you actually wanted all those backslashes in the name. In that case you need
echo 'Text\n' > \\\*\\\\\'\"Text in Here\"\\\'\\\\\*\$\\\?\\\*\\\*\\\*\\\*\\\*:\)
Don't bother trying to escape individual characters. Limit the special characters you need to worry about by using single quotes. Then, the single quote is the only character you need to worry about, and you get it by enclosing it in double quotes. Eg:
echo 'Text\n' > '\*\\'"'"'"Text in Here"\'"'"'\\*$\?\*\*\*\*\*:)'
Better yet, choose a simpler name. :)
I want to modify a string with replace in Smarty.
{$var|replace:'aaa':'bbb'}
Simple. But I need to replace this:
{$var|replace:'value="AA"':'value="$string_b"'}
I've also tried with the following syntax with no success:
{$var|replace:'value="AA"':'value="'$string_b'"'}
{$var|replace:'value="AA"':'value="`$string_b`"'}
{$var|replace:'value="AA"':'value=""$string_b""'}
you have to enclose the string in double quotes if you want smarty to recognize variables inside, so in your case you also have to escape the double quotes inside the string:
{$var|replace:'value="AA"':"value=\"{$string_b}\""}
Using brackets around the variable is not necessary but recommended
In the end I managed to find the right syntax to use.
{$var|replace:"value=\"AA\"":"value=\"$string\"}
I'm having a bit of trouble using parenthesis in a vim string. I just need to add a set of parenthesis around 3 digits, but I can't seem to find where I'm suppose to correctly place them. So for example; I would have to place them around a phone number such as: 2015551212.
Right now I have a strings that separates the numbers and puts a hyphen between them. For example; 201 555-1212. So I just need the parenthesis. The final result should look like: (201) 555-1212
The string I have so far is this: s/\(\d\{3}\)\(\d\{3}\)/\1 \2-/g
How might I go about doing this?
Thanks
Just add the parens around the \1 in your replacement.
s/\(\d\{3\}\)\(\d\{3\}\)/(\1) \2-/g
If you want to go in reverse, and change "(800) 555-1212" to "8005551212", you can use something like this:
s/(\(\d\d\d\))\ \(\d\d\d\)-\(\d\d\d\d\)/\1\2\3/g
Instead of the \d\d\d, you could use \d\{3\}, but that is more trouble to type.
I'm trying to use both tabs and newlines as delimiters to read from a .txt file. What I have at the moment is:
Scanner fileScanner = new Scanner(new FileReader("propertys.txt"));
fileScanner.useDelimiter("[\\t\\n]");
I've tried:
fileScanner.useDelimiter("\\t|\\n");
and
fileScanner.useDelimiter("[\\t|\\n]");
I've got no idea what's going wrong, I've searched around a lot and it looks like one of those should be working. Clearly I'm doing something wrong.
fileScanner.useDelimiter("\t|\n");
should work.
If you have two slashes "\n" the first acts as an escape and it won't work right.
For the regular expression used as a parameter in useDelimiter method, you should use newline as \n instead of \\n and tab as \t instead of \\t. From Java Pattern class: http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html.
A part from that, I think you should define you regular expression like, for example, this:
fileScanner.useDelimiter("\\s*[\t\n]\\s*");
to limit strings (\\s) between newline or tab characters.
I have something akin to <Foobar Name='Hello There'/> and need to change the single quotation marks to double quotation marks. I tried :s/\'.*\'/\"\0\" but it ended up producing <Foobar Name="'Hello There'"/>. Replacing the \0 with \1 only produced a blank string inside the double quotes - is there some special syntax I'm missing that I need to make only the found string ("Hello There") inside the quotation marks assign to \1?
There's also surround.vim, if you're looking to do this fairly often. You'd use cs'" to change surrounding quotes.
You need to use groupings:
:s/\'\(.*\)\'/\"\1\"
This way argument 1 (ie, \1) will correspond to whatever is delimited by \( and \).
%s/'\([^']*\)'/"\1"/g
You will want to use [^']* instead of .* otherwise
'apples' are 'red' would get converted to "apples' are 'red"
unless i'm missing something, wouldn't s/\'/"/g work?
Just an FYI - to replace all double quotes with single, this is the correct regexp - based on rayd09's example above
:%s/"\([^"]*\)"/'\1'/g
You need to put round brackets around the part of the expression you wish to capture.
s/\'\(.*\)\'/"\1"/
But, you might have problems with unintentional matching. Might you be able to simply replace any single quotes with double quotes in your file?
You've got the right idea -- you want to have "\1" as your replace clause, but you need to put the "Hello There" part in capture group 1 first (0 is the entire match). Try:
:%/'\(.*\)'/"\1"
Shift + V to enter visual block mode. Highlight the lines of code you want to remove single quotes from.
Then hit : on keyboard
Then type
s/'//g
Press Enter.
Done. You win.
Presuming you want to do this on an entire file ...
N Mode:
ggvG$ [SHIFT+:]
X Mode:
'<,'>/'/" [RET]