irfantak
asked on
ASP .NET String Assignment Problem
Strange ASP .NET Problem!
In the following code:
Response.Write(totalArrayT emp[0] + " - " + totalArrayTemp[1] + " - " + totalArrayTemp[2] + "<br>");//FINE!
shows the values of each variables fine. But , outside of the For Loop, the
Response.Write("TOTAL OWNER " + totalOwner.ToString());
Response.Write("TOTAL IDLE " + totalIdle);
Response.Write("TOTAL CONDOR " + totalCondor.ToString() + "<br>");
Don't show the output. What is even bizarre is that if I comment out the output in the For loop then
Response.Write("TOTAL OWNER " + totalOwner.ToString());
shows fine. And totalIdle and totalCondor never show any output outside of the For loop.
Seems to me like something wrong with using the StringBuilder() coding but how else can I achieve this? Basically, I need to have three variables (string type) to show data as:
totalOwner = "23, 44, 55, 66 77...";
totalIdle = "11, 22, 33, 44, 55....";
totalCondor = "99,88,77, 66, 55....";
Thanks
-------------------------- --
....
string[] totalArray = totalData.ToString().Split (new char[] { '#' });
system.Text.StringBuilder totalOwner = new System.Text.StringBuilder( );
System.Text.StringBuilder totalIdle = new System.Text.StringBuilder( );
System.Text.StringBuilder totalCondor = new System.Text.StringBuilder( );
for (int i = 0; i < totalArray.Length; i++) {
//let's get the data for TotalOwner
//Response.Write(totalArra y[i].ToStr ing() + "<br>");
string[] totalArrayTemp = totalArray[i].ToString().S plit(new char[] { ','});
Response.Write(totalArrayT emp[0] + " - " + totalArrayTemp[1] + " - " + totalArrayTemp[2] + "<br>");
totalOwner.Append(totalArr ayTemp[0] + ",");//total Owner
totalIdle.Append(totalArra yTemp[1] + ",");//total Idle
totalCondor.Append(totalAr rayTemp[2] + ",");//total Condor
}
Response.Write("TOTAL OWNER " + totalOwner.ToString());
Response.Write("TOTAL IDLE " + totalIdle);
Response.Write("TOTAL CONDOR " + totalCondor.ToString() + "<br>");
-------------------------- -----
In the following code:
Response.Write(totalArrayT
shows the values of each variables fine. But , outside of the For Loop, the
Response.Write("TOTAL OWNER " + totalOwner.ToString());
Response.Write("TOTAL IDLE " + totalIdle);
Response.Write("TOTAL CONDOR " + totalCondor.ToString() + "<br>");
Don't show the output. What is even bizarre is that if I comment out the output in the For loop then
Response.Write("TOTAL OWNER " + totalOwner.ToString());
shows fine. And totalIdle and totalCondor never show any output outside of the For loop.
Seems to me like something wrong with using the StringBuilder() coding but how else can I achieve this? Basically, I need to have three variables (string type) to show data as:
totalOwner = "23, 44, 55, 66 77...";
totalIdle = "11, 22, 33, 44, 55....";
totalCondor = "99,88,77, 66, 55....";
Thanks
--------------------------
....
string[] totalArray = totalData.ToString().Split
system.Text.StringBuilder totalOwner = new System.Text.StringBuilder(
System.Text.StringBuilder totalIdle = new System.Text.StringBuilder(
System.Text.StringBuilder totalCondor = new System.Text.StringBuilder(
for (int i = 0; i < totalArray.Length; i++) {
//let's get the data for TotalOwner
//Response.Write(totalArra
string[] totalArrayTemp = totalArray[i].ToString().S
Response.Write(totalArrayT
totalOwner.Append(totalArr
totalIdle.Append(totalArra
totalCondor.Append(totalAr
}
Response.Write("TOTAL OWNER " + totalOwner.ToString());
Response.Write("TOTAL IDLE " + totalIdle);
Response.Write("TOTAL CONDOR " + totalCondor.ToString() + "<br>");
--------------------------
After call to first Responce.Write() execution control shifts back to ASP.NET and whatever code you have after it is never executed. Use one StringBuilder or combined multiple of them object to build single output string and ten use Responce.Write()
ASKER
Dont quite understand you. I do need three different Stringbuilder objects (totalOwner, totalIdle, totalCondor). Could you please write me a little psedo-code? By the way, the Response.Write within the loop is just for debugging purposes and commeting it out did not solve the problem.
Thanks!
Thanks!
ASKER
This is just frustratingly strange. Look at this modified code. If I get the value of totalArrayTemp[1] to totalOwner, instead of the needed totalArrayTemp[0] then totalOwner does not get any values. And if I do debugging output within the loop then I can see that totalArrayTemp[1] does output correct values.
Any ideas?
----------------
for (int i = 0; i < totalArray.Length; i++) {
string[] totalArrayTemp = totalArray[i].ToString().S plit(new char[] { ','});
totalOwner.Append(totalArr ayTemp[1] + ",");//total Owner
//totalIdle.Append(totalAr rayTemp[1] + ",");//total Owner
}
Response.Write("TOTAL OWNER " + totalOwner.ToString() + "<br>" + totalIdle.ToString());
Any ideas?
----------------
for (int i = 0; i < totalArray.Length; i++) {
string[] totalArrayTemp = totalArray[i].ToString().S
totalOwner.Append(totalArr
//totalIdle.Append(totalAr
}
Response.Write("TOTAL OWNER " + totalOwner.ToString() + "<br>" + totalIdle.ToString());
ASKER
Okay, may be I am making it more complicated then it needs to be. But how can I parse a comma separated string like below into totalOwner, totalIdle, totalCondor. In my code above, totalArrayTemp is the one which gets populated with a string like this:
--------------
59.2 ,1202.8 ,0.0
--------------
59.2 ,1202.8 ,0.0
ASKER
Correction to my above post: Sorry, it would be totalArray which gets populated with a string like 59.2,1208.8,0.0
Get rid of Responce.Write inside loop,
Instead of
Response.Write("TOTAL OWNER " + totalOwner.ToString());
Response.Write("TOTAL IDLE " + totalIdle);
Response.Write("TOTAL CONDOR " + totalCondor.ToString() + "<br>")
use
Response.Write( string.Format( "TOTAL OWNER {0} TOTAL IDLE {1} TOTAL CONDOR {2} <br>", totalOwner.ToString(), totalIdle, totalCondor.ToString() );
Instead of
Response.Write("TOTAL OWNER " + totalOwner.ToString());
Response.Write("TOTAL IDLE " + totalIdle);
Response.Write("TOTAL CONDOR " + totalCondor.ToString() + "<br>")
use
Response.Write( string.Format( "TOTAL OWNER {0} TOTAL IDLE {1} TOTAL CONDOR {2} <br>", totalOwner.ToString(), totalIdle, totalCondor.ToString() );
ASKER
Thanks. But nothing outputs with this change. Here is the new code. Please help! I have spent too much time on it already. Seems to me like something to do with Stringbuilder?
------------------
System.Text.StringBuilder totalOwner = new System.Text.StringBuilder( );
System.Text.StringBuilder totalIdle = new System.Text.StringBuilder( );
System.Text.StringBuilder totalCondor = new System.Text.StringBuilder( );
for (int i = 0; i < totalArray.Length; i++) {
string[] totalArrayTemp = totalArray[i].ToString().S plit(new char[] { ','});
totalOwner.Append(totalArr ayTemp[0] + ",");//total Owner
totalIdle.Append(totalArra yTemp[1] + ",");//total Owner
totalCondor.Append(totalAr rayTemp[2] + ",");//total Owner
}
------------------
System.Text.StringBuilder totalOwner = new System.Text.StringBuilder(
System.Text.StringBuilder totalIdle = new System.Text.StringBuilder(
System.Text.StringBuilder totalCondor = new System.Text.StringBuilder(
for (int i = 0; i < totalArray.Length; i++) {
string[] totalArrayTemp = totalArray[i].ToString().S
totalOwner.Append(totalArr
totalIdle.Append(totalArra
totalCondor.Append(totalAr
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, let me try this....
Thanks!
Thanks!
ASKER
Yes,
http://68.159.97.140/RichChartServer/examples/DataSources/_tempstrings.aspx
the output does show up using your code above. I wonder what is causing my code to fail! Let me take a closer look...
Thanks.
http://68.159.97.140/RichChartServer/examples/DataSources/_tempstrings.aspx
the output does show up using your code above. I wonder what is causing my code to fail! Let me take a closer look...
Thanks.
ASKER
Hey, it works now!
http://68.159.97.140/RichChartServer/examples/DataSources/irf_scraping.aspx
Thanks a bunch for your help and patience!
http://68.159.97.140/RichChartServer/examples/DataSources/irf_scraping.aspx
Thanks a bunch for your help and patience!
ASKER
No, sorry, I spoke too soon. The output in the above page is simply what the output has been working from the Loop. Let me double check as to what is going wrong.
ASKER
I see the difference between your code and my code. In my code, totalData is is defined in StringBuilder and gets populated in a loop (which you have not seen in my code). While in your code, totalData is a simple String variable.
//the following line is in a Loop
totalData.Append(LineData[ 1] + "#");//Get the second array element
PS. You are not obligated to help me further because I have already Closed the Questions and given you the points. But somehow I still need to figure out a solution.
//the following line is in a Loop
totalData.Append(LineData[
PS. You are not obligated to help me further because I have already Closed the Questions and given you the points. But somehow I still need to figure out a solution.
ASKER
Figured out: There was "#" at the very end of my totalData and that was unneeded. Attaching that to your harcoded values for totalData broke your code too.
Thanks for your help.
Thanks for your help.