I have looked and looked and look for a way to put a " in between 2 string objects.
I know you can use "\"" to get a quote or even #"""" for the same result.
string quote = "\"";
string cheatName = "UnlockTankLine(" + nationNum.ToString() + "," + quote +
nationTankName[1] + quote + ")";
m_cheater.ActivateCheat(cheatName);
I need a result of "UnlockTankLine(int, "name")"... but when i do the above i get something like
"UnlockTankLine(int, \"name\")" and this isn't working with a cmd line for our game.
NOW if i am dumb and \"name\" is the same thing as "name" and the problem might be somewhere else. The only reason why I think i am not being dumb is if i use a different cheat cmd that doesn't take a string it works fine. Example UnlockWholeTankLine(int) works
try
to use format
string cheatName = string.Format("UnlockTankLine({0},\"{1}\")",
nationNum.ToString(), nationTankName[1])
Related
Morning folks,
I have an ASP.Net C# page that pulls in a list of servers from a SQL box and displays the list of servers in a label. ("srv1,srv2,srv3"). I need to add double quotes around each of the servers names. ("srv1","srv2","srv3",)
Any help would be greatly appreached.
If you have string
string str = "srv1,srv2,srv3";
Then you can simply do
str = "\"" + str.Replace(",", "\",\"") + "\"";
Now str contains "srv1","srv2","srv3"
As far as I can understand, you are trying to use double quotes in a string.
If you want to use such,
you can use escape character:
("\"srv1\",\"srv2\",\"srv3\"",)
for the sake of simplicity, you can even convert it to a function:
private string quoteString(string serverName){
return "\"" + serverName + "\"";
}
Also, if you have already "srv1,srv2,srv3" format, find ',' characters in the string and add " before and after comma. Also, notice that you should add to first index and last index ".
I take data from four different pages and different domains.
1- .com
2- .co.uk
3- .ca
4- .co.jp
For all of the above i take number from Html and Convert them to Double using line:
string lowestSellerPrice = (Convert.ToDouble(fbalPrice) +
Convert.ToDouble(fbalsPrice)).ToString();
This works perfectly fine for the first 3 domains but for .co.jp even though there is always a number in fbalPrice and fbalsPrice it is always giving exception :
Input string was not in a correct format
Any suggestion as i have been struggling with this for too long now no result i also tried the try parse solution but no luck.
UPDATE:
See this:
I solved it like this :
The string were like " 1234" and " 111" and i then did Replace(" ",""); . And only number lift this however did not work so i did this:
if (fbalPrice.Contains(" "))
{
fbalPrice = fbalPrice.Remove(0, fbalPrice.IndexOf(" ") + 1).Replace(",","").Trim();
}
if(fbalsPrice.Contains(" "))
{
fbalsPrice = fbalsPrice.Remove(0, fbalsPrice.IndexOf(" ") + 1).Replace(",", "").Trim();
}
And then added them and it worked.
I know I must be being stupid here, but I can't work out why this code isn't working. I'm very new to Razor, so please go easy on me.
I have the following code in my markup: (I've cut it down to be as simple as I can make it while still reproducing the issue so that I can hopefully diagnose the issue easier)
string testVar = "test";
#testVar
It returns the following:
error CS0103: The name 'testVar' does not exist in the current context
I've tried using different names for the variable, I've tried having it use "var" instead of "string" for it's declaration, I've tried assigning various different values to it, I've tried surrounding the variable in brackets like #(testVar), but the issue is still there. It's very frustrating, because in another part of my code I have
string prop = #p.Name + " (" + #p.PropertyType + ") - " + #p.GetValue(#page, null).ToString() + "\r\n";
#prop
which works fine.
I can't think what could be causing it, and it's starting to frustrate me.
Thanks,
YM
In Razor when we want to write c# statements we have to tell it that from here c# code starts:
#{ // from here c# block starts
string testVar = "test";
} // here ends
Now if you want to access this variable in html you can do like this:
<span>#testVar</span>
When you are writing:
string prop = #p.Name + " (" + #p.PropertyType + ") - " + #p.GetValue(#page, null).ToString() + "\r\n";
it is considered as plain text and will be rendered on browser like "string prop = ..."
you have to tell that it is c# code by following way:
#{
string prop = #p.Name + " (" + #p.PropertyType + ") - " + #p.GetValue(#page, null).ToString() + "\r\n";
}
have problem with delimited on one PC but on mine is everything good.
I have WinXP but my friend Vista.
Here is the code:
string AccessKonekcija2 = null;
AccessKonekcija2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\exports_blaise2\\" + textBox22.Text + ".mdb";
System.Data.OleDb.OleDbConnection AccessExcelKonekcija = new System.Data.OleDb.OleDbConnection(AccessKonekcija2);
System.Data.OleDb.OleDbCommand AccessExcelKomanda = new System.Data.OleDb.OleDbCommand();
AccessExcelKomanda.Connection = AccessExcelKonekcija;
AccessExcelKomanda.CommandText = "SELECT * INTO[Text;HDR=Yes;FMT=Delimited;DATABASE=C:\\exports_blaise2\\zips\\manipulai\\" + value3 + "\\" + textBox22.Text + "\\OUT].[" + value3 + "man.txt] FROM " + value3 + "man";
AccessExcelKonekcija.Open(); AccessExcelKomanda.ExecuteNonQuery();
AccessExcelKonekcija.Close();
And the error is:
Can someone tell me whats wrong ?
And how come that I can do that w/o an error.
But my friend not.
I already checked regional setting they are both equal.
Check the Regional Settings in Control Panel: One of the things you can set is the list separation character. The error message sounds like this could be the case. Since Excel respects this setting for CSV files and your code mentions Excel somewhat... give it a try?
Make sure they match. Standard (US) is ,. Here in Switzerland, though, it is normally ; and this can lead to subtle errors like the one you're having...
I don't know what is wrong with the following string:
"Report(" + System.DateTime.Now.ToString("dd-MMM-yyyy") + " to " + System.DateTime.Now.AddMonths(-1).ToString("dd-MMM-yyyy") + ")"
I can't get the concatenated string. I am getting Report(29-Dec-2009. That's all and
the rest gets left out from the string.
What is the reason?
Try this:
string filename =
String.Format(
"Report({0:dd-MMM-yyyy} to {1:dd-MMM-yyyy})",
System.DateTime.Now, System.DateTime.Now.AddMonths(-1));
EDIT: Since in your download box you got your filename broken in first whitespace, you could to try ONE of these:
filename = HttpUtility.UrlEncode(filename); // OR
filename = """" + filename + """";
Seems some browsers doesn't handles whitespaces very nicely: Filenames with spaces are truncated upon download. Please check it you can to download other filenames with whitespace in other sites.
You need to assign it to something:
string s = "Report(" + System.DateTime.Now.ToString("dd-MMM-yyyy") + " to " + System.DateTime.Now.AddMonths(-1).ToString("dd-MMM-yyyy") + ")"
Update: I just saw your update to the question. How are you displaying the string? I'm guessing that you are displaying it in a GUI and the label is too short to display the complete text.
Try this:
string newstring =
string.Format(
"Report ({0} to {1})",
System.DateTime.Now.ToString("dd-MMM-yyyy"),
System.DateTime.Now.AddMonths(-1).ToString("dd-MMM-yyyy")
);
What are you assigning the result to? It would be easier to read the code if you used string.Format
You are not assigning the concatenated result to anything, so can't use it:
string myConcatenated = "Report(" + System.DateTime.Now.ToString("dd-MMM-yyyy") + ")";
Using this code...
string test = "Report(" + System.DateTime.Now.ToString("dd-MMM-yyyy") + " to " +
System.DateTime.Now.AddMonths(-1).ToString("dd-MMM-yyyy") + ")";
I saw the following result.
Report(29-Dec-2009 to 29-Nov-2009)
It could be that the string is being truncated later on. Make sure that you set a breakpoint right after this code is run and check the value of the variable to which it is assigned (test in my case).
If, as in your previous question, you are using this value to create a file, it may be that it's the space before "to" that is causing the problem. Try to use:
"Report("
+ System.DateTime.Now.ToString("dd-MMM-yyyy")
+ "To"
+ System.DateTime.Now.AddMonths(-1).ToString("dd-MMM-yyyy")
+ ")"
instead and see if that fixes it.
If that does fix it, you'll probably need to either figure out how to quote the entire file name so it's not treated as the three separate arguments, "Report(29-Dec-2009", "to" and "29-Nov-2009)". Or simply leave your reports names without spaces.
I'd choose the latter but then I'm fundamentally opposed to spaces in filenames - they make simple scripts so much harder to write :-)