Difference between "" and String.Empty() [duplicate] - string

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is the difference between String.Empty and “”
What is the difference between code and where it is applicable??
string mystr = "";
string mystr1 = String.Empty();

The answer appears to be 'nothing'.
However, good programming practice says that you should preferably use string.Empty, as if in the future an empty string were to be represented by something other than "", your code otherwise might break. (I can't see tha change happening, but in principle it might).

I think this will explain it for you: http://msdn.microsoft.com/en-us/library/system.string.empty.aspx

Related

difference between « Michael » and « michael » [duplicate]

This question already has answers here:
How do I do a case-insensitive string comparison?
(15 answers)
Closed 7 months ago.
I’m new with Python. Just One question.
I try to create a mini quizz game and i want avoid this :
Answer = Input(« « «  Who sing : « Thriller » ? » » »)
If answer == « Michael Jackson »:
Print(« Good. »)
Else:
Print(« Wrong. »)
The problem is that if the user answer «michael jackson », the code run with wrong.
How can i fixed that?
Thanks
The way that this is usually done is to just turn all the input to lowercase. This can be done with the .lower() method on the input string. The corrector answer would then be "michael jackson".

Python, what is this for loop doing? [duplicate]

This question already has answers here:
What does "list comprehension" and similar mean? How does it work and how can I use it?
(5 answers)
Closed 3 years ago.
I have scoured the internet and I cannot find any reference to this type of for loop:
variable = [(item["attribute1"], item["attribute2]") for item in piece_of_json_data]
I am using this to update wtform's SelecField choices:
form.SelectField.choices = variable
but I can only get it to work if I replace one of the attributes in parenthesis with a static number:
variable = [(1, item["attribute2"]) for item in piece_of_json_data]
but that sets the value of the option field to "1", when I need the option values to be one of the attributes as a string.
Does this create a dict? a tuple? is there some kind of terminology for this that I can use to find documentation?
Thanks to the comments, I now understand that I am using list comprehension to create a tuple. The tuple works fine with both string and integer values. My issue has to do with .choices not accepting a string.
I found that my only problem is that I had coerce set to int on my selectfield, so naturally it wanted an integer.

What is the right operator in vb.net for test if a String is not equal? [duplicate]

This question already has answers here:
Is there a VB.net equivalent for C#'s ! operator?
(6 answers)
Closed 3 years ago.
I tried something like this
Do Until !test.equals("1234") Or !test.equals("xyxyxyx")
...
Loop
How can I write that in vb.net?
The ! in other language is Not is vb.net
Do Until Not test.equals("1234") Or Not test.equals("xyxyxyx")
I believe this is what you're looking for:
https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference///operators/comparison-operators
Do Until test <> 1234 Or test <> "xyxyxyx"
...
Loop
Try this
Do While test <> "1234" or test <> "xyxyxyx"
//your code here...
Loop
From Microsoft Documentation
Do Loop Statement(visual Basic)
Comparison operators in Visual Basic

Split string in Lua, save in 2 variables [duplicate]

This question already has answers here:
Split string in Lua?
(18 answers)
Closed 9 years ago.
I have one string, that is = s = "Pedro Martinez, Defense"
I want to split the string before the comma and after the comma, store those cuts on 2 variables, for example:
I think that I need to use the string.gmatch function or string.sub
How can I do that?
The accepted answer at How to convert GPS coordinates to decimal in Lua? shows how to use string.match and patterns. Applying the same techniques as mentioned there, you could use
local name, expertise = string.match(s, "(.*),%s*(%a*)")
which would lead to name being "Pedro Martinez" and expertise being "Defense".

PHP Strict Standards on line with variable [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Annoying PHP error: “Strict Standards: Only variables should be passed by reference in”
I have this line of code,
$extension=end(explode(".", $srcName));
when I fun my function I get
PHP Strict Standards: Only variables should be passed by reference in
I am not sure how to solve this
The function end() requires a variable to be passed-by-reference and passing the return-value of a function doesn't acheive this. You'll need to use two lines to accomplish this:
$exploded = explode(".", $srcName);
$extension = end($exploded);
If you're simply trying to get a file-extension, you could also use substr() and strrpos() to do it in one line:
$extension = substr($srcName, strrpos($srcName, '.'));
Or, if you know the number of .'s that appear in the string, say it's only 1, you can use list() (but this won't work if there is a dynamic number of .'s:
list(,$extension) = explode('.', $srcName);

Resources