How to generate "1. Do the homework" from "#Model.Number. #Model.Task" in razor? - asp.net-mvc-3

I need to generate a string which looks like variable, dot, space, another variable.
The #Model.Number. #Model.Task or #(Model.Number). #(Model.Task) or #{Model.Number}. #{Model.Task} doesn't seem to compile.
The #Model.Number<text>. </text>#Model.Task works, but it generates a trashy <text> tag in the resulting html.
If I place all of these on a separate line:
#Model.Number
.
#Model.Task
then the result will render with an extra space between the number and the dot.
The #Model.Number#:. #Model.Task doesn't compile either.

Try this:
#(Model.Number). #Model.Task

Another solution:
#(Model.Number + ". " + Model.Task)

Related

XPATH remove extra spaces in concatenation of elements

In XPATH, I am treating a source XML that looks like below, where I want to concatenate the child elements of each editor with a space delimiter to create a full name, and then in turn concatenate the resulting full names with commas:
<biblStruct type="book" xml:id="Biller_2011a">
<monogr>
<title>Inquisitors and Heretics in Thirteenth-Century Languedoc: Edition and Translation
of Toulouse Inquisition Depositions, 1273-1282</title>
<editor>
<forename>Peter</forename><surname>Biller</surname>
</editor>
<editor>
<forename>Caterina</forename><surname>Bruschi</surname>
</editor>
<editor>
<forename>Shelagh</forename><surname>Sneddon</surname>
</editor>
<imprint>
<pubPlace>
<settlement>Leiden</settlement>
<country>NL</country>
</pubPlace>
<publisher>Brill</publisher>
<date type="pub_date">2011</date>
</imprint>
</monogr>
</biblStruct>
Currently the XPATH (within XQuery) code looks like this, using XPATH map to introduce delimiters:
let $bibref := $bib//tei:biblStruct[#xml:id="Biller_2011a"]
return <editors>{
(for $auth in $bibref//tei:editor
return normalize-space(string-join($auth//child::text()," ")))!(if (position() > 1) then ', ' else (), .)
}</editors>
But this outputs extra space before and after the commas:
<editors>Peter Biller , Caterina Bruschi , Shelagh Sneddon</editors>
Rather, I want to output:
<editors>Peter Biller, Caterina Bruschi, Shelagh Sneddon</editors>
Thanks in advance.
"where I want to concatenate the child elements of each editor" would translate into $auth/* and not into $auth//child::text().
Somehow the whole mix of for return and ! and string-join looks odd, it seems you can just use string-join($bibref//tei:editor/string-join(*, ' '), ', ').

Removing Class Name of an element using element.className.replace method

var divfoo=document.getElementById("foo");
divfoo.className=" css-class css-class2 ";
divfoo.className=divfoo.className.replace(" css-class2 ", "");
The above code works. but I would like to make changes to last line of above code which is using replace method. Instead of writing the code like above, I would like to know why doesn't it work when written like below.
var divfoo=document.getElementById("foo");
divfoo.className=" css-class css-class2 ";
divfoo.className.replace(" css-class2 ", "");
Why should one assign to "divfoo.className" when applying replace method to the same "divfoo.className", why can't we just apply method directly like above code did?
Because of this should I hate javascript for not being logical?
enter code here
Element.className is a plain string representation of class HTML attribute.
String.replace method does not change the source string that is called on, just returns the result of replacement procedure.
If you want more "logical / functional" approach, look at Element.classList interface, namely the remove method.

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.

Replacing scan by gsub in Ruby: how to allow code in gsub block?

I am parsing a Wiki text from an XML dump, for a string named 'section' which includes templates in double braces, including some arguments, which I want to reorganize.
This has an example named TextTerm:
section="Sample of a text with a first template {{TextTerm|arg1a|arg2a|arg3a...}} and then a second {{TextTerm|arg1b|arg2b|arg3b...}} etc."
I can use scan and a regex to get each template and work on it on a loop using:
section.scan(/\{\{(TextTerm)\|(.*?)\|(.*?)\}\}/i).each { |item| puts "1=" + item[1] # arg1a etc.}
And, I have been able to extract the database of the first argument of the template.
Now I also want to replace the name of the template "NewTextTerm" and reorganize its arguments by placing the second argument in place of the first.
Can I do it in the same loop? For example by changing scan by a gsub(rgexp){ block}:
section.gsub!(/\{\{(TextTerm)\|(.*?)\|(.*?)\}\}/) { |item| '{{NewTextTerm|\2|\1}}'}
I get:
"Sample of a text with a first template {{NewTextTerm|\\2|\\1}} and then a second {{NewTextTerm|\\2|\\1}} etc."
meaning that the arguments of the regexp are not recognized. Even if it worked, I would like to have some place within the gsub block to work on the arguments. For example, I can't have a puts in the gsub block similar to the scan().each block but only a string to be substituted.
Any ideas are welcome.
PS: Some editing: braces and "section= added", code is complete.
When you have the replacement as a string argument, you can use '\1', etc. like this:
string.gsub!(regex, '...\1...\2...')
When you have the replacement as a block, you can use "#$1", etc. like this:
string.gsub!(regex){"...#$1...#$2..."}
You are mixing the uses. Stick to either one.
Yes, changing the quote by a double quote isn't enough, #$1 is the answer. Here is the complete code:
section="Sample of a text with a first template {{TextTerm|arg1a|arg2a|arg3a...}} and then a second {{TextTerm|arg1b|arg2b|arg3b...}} etc."
section.gsub(/\{\{(TextTerm)\|(.*?)\|(.*?)\}\}/) { |item| "{{New#$1|#$3|#$2}}"}
"Sample of a text with a first template {{NewTextTerm|arg2a|arg3a...|arg1a}} and then a second {{NewTextTerm|arg2b|arg3b...|arg1b}} etc."
Thus, it works. Thanks.
But now I have to replace the string, by a "function" returning the changed string:
def stringreturn(arg1,arg2,arg3) strr = "{{New"+arg1 + arg3 +arg2 + "}}"; return strr ; end
and
section.gsub(/\{\{(TextTerm)\|(.*?)\|(.*?)\}\}/) { |item| stringreturn("#$1","|#$2","|#$3") }
will return:
"Sample of a text with a first template {{NewTextTerm|arg2a|arg3a...|arg1a}} and then a second {{NewTextTerm|arg2b|arg3b...|arg1b}} etc."
Thanks to all!
There is probably a better way to manipulate arguments in MediaWiki templates using Ruby.

is there a way to get codeigniter to create a plain text page where \n char works properly?

I am trying to use vanilla forum with proxyconnect and it requires i give it a plain text file of my user's authentication cookie values in the form below. However, when i send it the only way i can get it to work is with the tags and i needs to have the \n tag.
document should be:
UniqueID=5
Name=Kyle
Email=email#email.com
I can get it to display like that with br tags but when i use \n tags they show up like this:
UniqueID=5\nName=Kyle\nEmail=email#email.com
here is the method in the controller
function get_user_info(){
if(!empty($this->user)){
printf('UniqueID=' . $this->user['userID'] . '\n');
printf('Name=' . $this->user['userFirst'] . '\n');
printf('Email=' . $this->user['userEmail'] . '\n');
}
}
Try to use use "\n" with double quotes instead. Special characters will not be expanded when they occur in single quoted strings.
Example
printf('Name=' . $this->user['userFirst'] . "\n");
Along with what rkj has suggested above, you need to output the page as plain text. To do this, add this to the beginning of your controller's function:
$this->output->set_header("Content-Type: text/plain");

Resources