[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

escape characters won't work why?

This should produce a nice table, but it does not work. It looks like escape characters not work. I print the text in an asp label.


private string GetTableData(DataTable dt)
    {

        StringBuilder TableData = new StringBuilder();
        // retrieve header row column labels
        TableData.AppendFormat("Row");
        foreach (DataColumn dc in dt.Columns)
        {
            TableData.AppendFormat("/t{0}", dc.ColumnName);
            TableData.AppendFormat("/t");
        }

        // retrieve rows
        int j = -1;
        foreach (DataRow dr in dt.Rows)
        {
            TableData.AppendFormat("[{0}]", ++j);
            foreach (DataColumn dc in dt.Columns)
            {
                TableData.AppendFormat("/t{0}", dr[dc]);
            }
            TableData.AppendFormat("/n");
        }

        return TableData.ToString();
    }
0
m-jansen
Asked:
m-jansen
  • 5
  • 4
2 Solutions
 
AdGrootCommented:
use the \ in place of the /

Change /t  to \t
and /n to \n

Ad
0
 
m-jansenAuthor Commented:
sorry that does not work either
0
 
AdGrootCommented:
Strange

I try this

            StringBuilder TableData = new StringBuilder();
            TableData.AppendFormat("AA\tKK\tBB");
            TableData.AppendFormat("\n");
            TableData.AppendFormat("AAB\tBBK\tKK");
            Debug.WriteLine(TableData.ToString());

with gives me as result

AA      KK      BB
AAB      BBK      KK
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
m-jansenAuthor Commented:
With this code
        StringBuilder TableData = new StringBuilder();
        TableData.AppendFormat("AA\tKK\tBB");
        TableData.AppendFormat("\n");
        TableData.AppendFormat("AAB\tBBK\tKK");
        lblTest.Text = TableData.ToString(); //asp lable
I get just this is the output.

AA KK BB AAB BBK KK

Debug.WriteLine(TableData.ToString()); does not work in my asp.net 2.0 website in VS
0
 
AdGrootCommented:
A supose the asp label have some problems with the tabs

you can try this

           TableData.AppendFormat("/t{0,10}", dc.ColumnName);

Ad

0
 
AdGrootCommented:
For left align try

           TableData.AppendFormat("/t{0,-10}", dc.ColumnName);

Ad

0
 
AdGrootCommented:
For a newline you kan try to insert a <br> in TableData

Ad
0
 
m-jansenAuthor Commented:
It have problems with newline too. What to use instead of "\n"
0
 
m-jansenAuthor Commented:
thanks alot. so it's html I must use as reference when using escape characters in asp?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now