Tagged Questions
8
votes
6answers
6k views
Dollar ($) sign in password string treated as variable
Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems connecting to the database. The database could be accessed from the shell and phpMyAdmin with the ...
118
votes
34answers
173k views
How to trim whitespace from bash variable?
I have a shell script with this code:
var=`hg st -R "$path"`
if [ -n "$var" ]; then
echo $var
fi
But the conditional code always executes because hg st always prints at least one newline ...
3
votes
4answers
8k views
Python: Using vars() to assign a string to a variable
I find it very useful to be able to create new variables during runtime and create a dictionary of the results for processing later, i.e. writing to a file:
myDict = {}
for i in range (1,10):
...
28
votes
9answers
22k views
PHP - concatenate or directly insert variables in string
I am wondering, What is the proper way for inserting PHP variables into a string?
This way:
echo "Welcome ".$name."!"
Or this way:
echo "Welcome $name!"
Both of these methods work in my PHP ...
5
votes
5answers
33k views
How do I put variable values into a text string in MATLAB?
I'm trying to write a simple function that takes two inputs, x and y, and passes these to three other simple functions that add, multiply, and divide them. The main function should then display the ...
14
votes
10answers
7k views
How to get a variable name as a string in Python?
I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:
>>> print(my_var.__name__)
'my_var'
I ...
10
votes
2answers
3k views
How to determine if a string is a valid variable name?
I'm looking for a quick way (in C#) to determine if a string is a valid variable name. My first intuition is to whip up some regex to do it, but I'm wondering if there's a better way to do it. Like ...
3
votes
5answers
3k views
javascript string to variable
I am receiving a JSON string from an ajax call and would like to convert a value to a predefined variable:
var predefined = "hello world";
var foo = {"msg":"predefined"}; // JSON string
I want to ...
0
votes
5answers
572 views
How to convert a string value to a variable in javascript?
var test1;
$(document).ready(function () {
test1 = $("#test1ID").jQueryPlugin();
});
var test2;
$(document).ready(function () {
test2 = $("#test2ID").jQueryPlugin();
});
...
This is done ...
3
votes
7answers
3k views
PHP - replace a string with a variable named like the string
so the string is like this:
"bla bla bla {VARIABLE} bla bla"
when I use this string somewhere in a function I want to replace {VARIABLE} with $variable (or any other uppercase strings with wrapped ...
10
votes
11answers
14k views
Convert Variable Name to String?
I would like to convert a python variable name into the string equivalent as shown. Any ideas how?
var = {}
print ??? # Would like to see 'var'
something_else = 3
print ??? # Would print ...
7
votes
6answers
875 views
String and Final
What is difference between in the following statements
String name = "Tiger";
final String name ="Tiger";
Although the String class is final class, why do we need to create a String "CONSTANT" ...
6
votes
4answers
2k views
converting a variable name to a string in C++
I'd like to output some data to a file. For example assume I have two vectors of doubles:
vector<double> data1(10);
vector<double> data2(10);
is there an easy way to output this to a ...
3
votes
2answers
122 views
Variable not Initialized - Although I am?
Answered
Mike Suggested I added some code to the
default:
break;
part of the switch, I added an exception to it, and no need to change anything else. Code now runs successfully. Thanks guys!
...
8
votes
5answers
14k views
JavaScript Variable inside string without concatenation - like PHP
I know in PHP we can do something like this :
$hello = "foo";
$my_string = "I pity the $hello";
output : "I pity the foo"
I was wondering if this same thing is possible in JavaScript as well. ...