Seperate initials in freemarker - freemarker

Is it possible to set points in initials?
For example to change MAW into M.A.W.
I tried keep_before, but it doesn't work.
?keep_before(" ")+". "}
Result: MAW.
Please help.

You could do it like:
${'MAW'?replace('','.')[1..]}
'MAW'?replace('','.') will result in .M.A.W., which you can "substring" by using the range [1..].
See
https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_replace
https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_stringop_slice

It's easiest to do with regular expressions: ${initials?replace('.', '$0.', 'r')}. It's maybe nicer if you wrap this into a #function though (<#function dotify(s)><#return s?replace('.', '$0.', 'r')></#function>, and then ${dotify(initals)}), especially if you need to do this on multiple places.

If your letters are in name try:
<#list 0..(name?length-1) as idx>${name[idx]}.</#list>

Related

remove `\"` from string rails 4

I have params like:
params[:id]= "\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\""
And i want to get expected result as below:
"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
How can I do this?
You can use gsub:
"\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\"".gsub("\"", "")
=> "ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
Or, as #Stefan mentioned, delete:
"\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\"".delete("\"")
=> "ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
If this is JSON data, which it could very well be in that format:
JSON.load(params[:id])
This handles things where there's somehow escaped strings in there, or the parameters are an array.
Just Use tr!
params[:id].tr!("\"","")
tr! will also change the main string
In case you do not want to change main string just use :
params[:id].tr("\"","")
Thanks Ilya

How to use gsub regex in ruby

I want to remove some part of string from using ruby regex:
value = localhost:8393/foobar/1 test:foobartest
I want to remove "test" from my string [localhost:8393/foobar/1 test:foobartest] and rest of the value so that output should look like:
localhost:8393/foobar/1
How to do this in ruby? Can you share some sample code to achieve this?
Appreciated your help in advance!
Thanks!
I would do something like this:
value = 'localhost:8393/foobar/1 test:foobartest'
value.split.first
#=> "localhost:8393/foobar/1"
Or if you want to use an regexp:
value.sub(/ test.*/, '')
"localhost:8393/foobar/1"

how to get this result ["a1","a2",..."a20"] in ruby?

("a1".."a5").to_a
result:["a1","a2","a3","a4","a5"]
why doesn't ("a1".."a20").to_a put ["a1","a2",..."a20"]?
I want to get your help ,thanks!
Its generate by ASCII order of every string, you can try ('1'..'z').to_a to see what happend. So your code will generate every posible that can. If you want to get ['a1', 'a2', .. 'a20'], use
(1..20).to_a.map {|i| "a#{i}" }

Printing this variable in smarty

I'm having an array $customPre. I want to print the element of the array "Please specify which fund". I am doing like this:
{$customPre.Please specify which fund}
But it's not working.
In this case you need to use PHP-like syntax that is similar to PHP: {$variable['key']}.
If In PHP you have:
$smarty->assign('customPre', array ('Please specify which fund' => 'This is value'));
In Smarty you need to use:
{$customPre['Please specify which fund']}
And the output for this will be:
This is value
I believe you cannot use in this case dot syntax ( {$customPre.Please specify which fund}) because it's probably looks for whitespaces in keys. Even adding quotes won't help.

Using not() in XPath

I would like how to use the "not" in XPath properly. I just can't seem to get it to work with attributes.
Say I have this expression: //*[#name = 'Bob'] It is valid, and will return all nodes that have a name attribute equaling 'Bob'.
Now if I want all nodes that have a name attribute that do not equal 'Bob', I need to use an XPath such as: //*[#name not(='Bob')] but this is invalid.
I have tried multiple combinations with not() being placed in a different order, but I can't seem to get this to work. Could someone please inform me how to use not() properly?
Also, does the order change when using elements instead of attributes? Such as: //name[text() = 'Bob']
Thanks! :)
According to : http://msdn.microsoft.com/en-us/library/ms256086.aspx, have you tried
//*[#name != 'Bob']
Try
//*[#name != 'Bob']
or
//*[not(#name = 'Bob')]
should work both.
//*[#name and #name != 'Bob']

Resources