|
Actually sir the thing is that event will also be called when code exit out of backup....so i think thats not an issue....The main thing is, the line
Process process=Process.Start(psi);
is not executing....and after this line i m getting error.....
|
|
|
|
|
Hi Everyone,
I am facing an issue in appending quotes to the string value that I am holding in a String Builder variable.
The value that I hold in the variable is,
abc@def@ghi@jkl@
I would like to change the @ with "," so that i get the final result as,
"abc","def","ghi","jkl"
I tried the string format, but did not succeed. Any help in this matter is greatly appriciated.
|
|
|
|
|
Replace perhaps?
But why create the string with the @ s rather than the characters you want? Creating the string the way you want shouldn't be a problem. Perhaps you should explain what you want and show the code you have so far.
|
|
|
|
|
try
{
oleDbDa.Fill(ds,"ServerName");
DataTable dt = ds.Tables["ServerName"];
foreach(DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dt.Columns)
strServerName.Append(dr[dc].ToString()).Append("\",\"");
}
Response.Write(strServerName);
}
But here again i need to get rid of of the quotations at the end of the string and need to add it before the string.
The result that is get is,
abc","def","ghi","jkl","
As I had mentioned i'd like to get the result as,
"abc","def","ghi","jkl"
|
|
|
|
|
How about:
foreach(DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dt.Columns)
strServerName.AppendFormat( "\"{0}\"," , dr[dc] );
}
strServerName.Length-- ;
|
|
|
|
|
Thanks PIEBALDconsult for the help. The solution is just perfect, but there is an extra comma at the end of the string,
"abc","def","ghi","jkl",
How could I get rid of the last comma?
|
|
|
|
|
You probably left off the decrement of the Length.
|
|
|
|
|
oops!!! I did miss that one out. After I included the decrement of the length, it is removing all the comma's from the string. I need the comma that is in between the strings but it should not add the comma at the end of the string.
It is just like the SQL statement that we write.
e.g. Select * from table where name like ('abc','def','ghi')
I am trying to send the variable in this format to the stored procedure.
|
|
|
|
|
It should be outside the loop, as in the example I posted.
|
|
|
|
|
|
Thanks, but I just tried this,
strHolderString = strServerName.ToString();
strHolderString = strHolderString.TrimEnd(',');
strFinalList = new StringBuilder(strHolderString);
here the strHolderString is a string variable and I am getting the result that I was looking for.
Thanks once again to everyone.
|
|
|
|
|
Just decrement the Length. Why create two Strings and another StringBuilder?
|
|
|
|
|
What Piebald said; or else what I often do when I do not want the StringBuilder:
string result="";
string sep="";
foreach(string s in strings) {
result+=sep+"\""+s+"\"";
sep=",";
}
|
|
|
|
|
I'd still use String.Format -- I find it easier to read than a bunch of concatenations.
|
|
|
|
|
I'd like to go with PIEBALDconsult on this one, but thanks for the help
|
|
|
|
|
I use it sparingly, string.Format I mean.
|
|
|
|
|
I use it whenever I can -- muaa haa ha ha!
|
|
|
|
|
strHolderString = strServerName.ToString();
strHolderString = strHolderString.TrimEnd(',');
strFinalList = new StringBuilder(strHolderString);
I just tried the above and it works for me. Here the strHolderString is a string variable and I used the TrimEnd function to get rid of the trailing comma. The strFinalList is a StringBuilder variable.
Thanks once again to all
|
|
|
|
|
There's pretty much no reason to avoid StringBuilder, it's in the core Framework and the memory footprint of creating a new object is likely to be less than all the wasted strings you make in a concatenation session.
|
|
|
|
|
Based on your posts below, have you tried using string.Join?
string example = String.Join(", ", string[] exList);
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
|
An alternative approach is to use a list of strings instead of a StringBuilder to build your list and then concatenate them as you need. Here's one way to do this:
public class FormattedStrings : List<string>()
{
public override string ToString()
{
StringBuilder sb = new StringBuilder();
bool started = false;
foreach (string item in this)
{
if (started)
{
sb.AppendFormat(",\"{0}\"", item);
}
else
{
started = true;
sb.AppendFormat("\"{0}\"", item);
}
}
return sb.ToString();
}
} I am assuming that you have assigned the @ symbol when you built your StringBuilder .
|
|
|
|
|
Ew, yuck, duplicated code. Needless boolean, needless if/else .
Stick the comma on the end and decrement it off when you're done.
|
|
|
|
|
To be fair, this was just knocked up in the CP editor and doesn't reflect what I would push out the door.
I did look at doing it your way, but saw that you'd already posted that so it seemed that there wasn't much point to showing something that was already done - this is purely to stimulate the mind into thinking of other ways of solving the problem.
|
|
|
|
|
I want to encrypt image by other image using Xor operation in c# as follow:
private byte[] EncypteXoRImage(byte[] inputImage, byte[] byImage)
{
byte[] Result = (byte[])inputImage.Clone();
if (byImage == null)
return Result;
for (int k = inputImage.Length / 3; k < inputImage.Length; k++)
{
Result.SetValue(Convert.ToByte((byte)Result.GetValue(k) ^ (byte)byImage.GetValue(k % byImage.Length)), k);
}
return Result;
}
where inputImage is picture which i want to encrypt,the problem is when i want to display encrypted picture on the picturebox,the result is:
the encrypted part was displayed by a gray background
|
|
|
|