Solved

escape characters won't work why?

Posted on 2006-06-24
9
228 Views
Last Modified: 2009-12-16
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
Comment
Question by:m-jansen
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:AdGroot
Comment Utility
use the \ in place of the /

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

Ad
0
 

Author Comment

by:m-jansen
Comment Utility
sorry that does not work either
0
 
LVL 5

Expert Comment

by:AdGroot
Comment Utility
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
 

Author Comment

by:m-jansen
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Assisted Solution

by:AdGroot
AdGroot earned 50 total points
Comment Utility
A supose the asp label have some problems with the tabs

you can try this

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

Ad

0
 
LVL 5

Expert Comment

by:AdGroot
Comment Utility
For left align try

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

Ad

0
 
LVL 5

Accepted Solution

by:
AdGroot earned 50 total points
Comment Utility
For a newline you kan try to insert a <br> in TableData

Ad
0
 

Author Comment

by:m-jansen
Comment Utility
It have problems with newline too. What to use instead of "\n"
0
 

Author Comment

by:m-jansen
Comment Utility
thanks alot. so it's html I must use as reference when using escape characters in asp?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now