Razor print variable near HTML number - asp.net-mvc

I have a really noob question for you today. Please keep in mind that this is my first project in Razor so don't be too harsh :)
The problem happens when I print variables to a template.
When it's a simple string I have no problem, but when it's a number it just doesn't print the value.
Works
string url = #CurrentPage.Site.Replace("http://", "").Replace("https://", "");
#url
// prints - www.google.pt
Doesn't work
string num = #CurrentPage.Telefone.Replace(" ", "");
#CurrentPage.Telefone
// prints - 123 456 789
Can anyone explain why this happens?
Thanks :)

You might consider checking this Quick Reference:
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/
#{
string num = #CurrentPage.Telefone.Replace(" ", "");
}
#CurrentPage.Telefone
You have to surround the num with () otherwise the razor engine thinks you are trying to add an email adress or something like that.

just put #CurrentPage.Telefone ;)

Try this:
string num = #CurrentPage.Telefone.Replace(" ", "");
#CurrentPage.Telefone
// prints - 123 456 789
Attempt to use #Html.Raw(num) instead of #num

Related

Remove the first word of a string in lua

What I'm looking for is something like the following, but it only applies to the first find it gets.
str:gsub("1", "")
I'd like it to only delete the first 1 it finds OR just the first word of the string.
How would I go about doing this?
try this:
local str = "234243 232564 se42"
local str, i = str:gsub("1", "",1)
print (str,i)
str = (i>0) and str or str:gsub("^.-%s", "",1)
print (str)
only when there are spaces in the string (more than one word).

Swift Adding HTML to UIWebView, expression was too complex

I'm adding some HTML content to an UIWebView.
This line:
generatedHtml += "<br><p style=\"font-family:'Chevin-Medium';font-size:12px;color:#505050;padding-top:0px;\">" + newsItem.entry.likes + " like this " + newsItem.entry.comments?.count + " comments</p>"
I get:
expressions was too complex to be solved in reasonable time
I'm just doing a count on an array, i don't know how to make that less complex?
The object looks like this:
public class NewsItem: NSObject {
var entry: EntryObject = EntryObject()
}
public class EntryObject: NSObject {
var comments: [Comment]? = []
}
newsItem.entry.comments?.count is an integer, and you can't add an integer to a string using +, you should use string interpolation with \():
" like this \(newsItem.entry.comments?.count) comments</p>"
Or use the String initializer if you need to keep using +:
" like this " + String(newsItem.entry.comments?.count) + " comments</p>"
If the error "too complex" persists, you'll have to break down the statements and use variables instead of inserting the expressions directly.
Try to do by this way
var countComments : Int = 0
//Validate comment counting
if let cComments = newsItem.entry.comments?.count
{
countComments = cComments
}
//... Some code here ...
//Devide to Conquest.
//If is easy to find... Is not hard to fix
generatedHtml += "<br>"
generatedHtml += "<p style=\"font-family:'Chevin-Medium';font-size:12px;color:#505050;padding-top:0px;\">"
generatedHtml += "\(newsItem.entry.likes) "
generatedHtml += "like this \(countComments) comments" //Here you have a valid value
genetatedHtml += "</p>"
But, why?
Maybe you have a problem with the optional value newsItem.entry.comments?.count that can gets you a nil value. Then, first of all, validate the value and be sure about what was returned. Better "0", a valid value than nil
When you split the string creation, the debug working will be more easy to execute. You will can have a better idea where is happening an error.
Maybe it´s not a definitive solution to your problem, but a good way to help you fix it.

Write to webpage letter by letter

So i'm busy with AutoIt, i am now using this code
_IEPropertySet($passwordnew, "innertext", "12345678910")
This will paste the text "12345678910" into the Textbox of the webpage, is it possible to let it type it letter for letter? Not that it paste the whole concept. I already tried several stuff but it resulted in many errors.
Why? You can try something like this:
Global $passwordnew = StringSplit(12345678910, '', 2)
Global $valueOfPasswortField = ''
For $i = 0 To UBound($passwordnew) - 1
;~ $valueOfPasswortField &= $passwordnew[$i]
;~ ConsoleWrite($valueOfPasswortField & #CRLF)
_IEPropertySet($passwordnew, "innertext", _IEPropertyGet($passwordnew, "innertext") & $passwordnew[$i])
Sleep(400)
Next
It seems to me that you need a OnKeyUp event fired
$password = "1234567890"
_IEPropertySet($passwordnew, "innertext", "12345678910")
BlockInput(1)
_IEAction($passwordnew, "focus")
Send($password, 1)
BlockInput(0)
or
_IEPropertySet($passwordnew, "innertext", "12345678910")
$passwordnew.fireEvent("onkeyup")

How can I loop textBox.text in Lua

I would like to set my textBox.text equal to 1\n\2\n3\n...\n100 I searched through the docs but do not find any solution.
I tried to use table with textBox. I used textBox.text = mutable but it doesn't work :(
Any help would be appreciated, Thanks :)
Simply loop for as many lines as you need:
function lineNumbers(num)
local content=''
for i=1,num-1 do
content = content .. i .. '\n'
end
return content .. num
end
textBox.text = lineNumbers(100)

Convert part of string to URL when displayed

I browsed around for a solution and I am sure it's a simple question but still not sure how to do that. So, I have a string that contains many words and some times it has links in it. For example:
I like the website http://somesitehere.com/somepage.html and I suggest you try it too.
I want to display the string in my view and have all links automatically converted to URLs.
#Model.MyText
Even StackOverflow gets it.
#Hunter is right.
In addition i found complete implementation in C#: http://weblogs.asp.net/farazshahkhan/archive/2008/08/09/regex-to-find-url-within-text-and-make-them-as-link.aspx.
In case original link goes down
VB.Net implementation
Protected Function MakeLink(ByVal txt As String) As String
Dim regx As New Regex("http://([\w+?\.\w+])+([a-zA-Z0-9\~\!\#\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.IgnoreCase)
Dim mactches As MatchCollection = regx.Matches(txt)
For Each match As Match In mactches
txt = txt.Replace(match.Value, "<a href='" & match.Value & "'>" & match.Value & "</a>")
Next
Return txt
End Function
C#.Net implementation
protected string MakeLink(string txt)
{
Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\#\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
MatchCollection mactches = regx.Matches(txt);
foreach (Match match in mactches) {
txt = txt.Replace(match.Value, "<a href='" + match.Value + "'>" + match.Value + "</a>");
}
return txt;
}
One way to do that would be to do a Regular Expression match on a chunk of text and replace that url string with an anchor tag.
Another regex that can be used with KvanTTT answer, and has the added benefit of accepting https urls
https?://([\w+?.\w+])+([a-zA-Z0-9\~!\##\$\%\^\&*()_-\=+\/\?.:\;\'\,]*)?
.net string representation:
"https?://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\#\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?"

Resources