2

I have a javascript function that has 5 parameters. I need to pass a large amount of text (it is a stack trace from C#.net code behind to the js function

Code :

function createDIV(CLASS_NAME, METHOD_NAME, APPLICATION_NAME, EXCEPTION_MESSAGE, STACK_TRACE_TEXT, EXCEPTION_OCCURANCE_STATUS) {   
    \\processing the code
}

When I call this function it works for all other values but if the text contains \n it fails

sample text : org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.\n\tat org.apache.struts.chain.commands.AbstractSelectAction.execute(AbstractSelectAction.java:68)\n\tat

Calling code:

ClientScript.RegisterStartupScript(
    GetType(), 
    "sss", 
    "createDIV(
        '" + CLASS_NAME.ToString() + "','" + METHOD_NAME.ToString() + "','" + 
            APPLICATION_NAME.ToString() + "','" + EXCEPTION_MESSAGE.ToString() + "','" + 
            STACK_TRACE.ToString() + "');",
true);

I'm also unable to replace the \n with its html equivalent in C#.net. it just returns -1 for its occurance

Please help

4

2 に答える 2

0

試すSTACK_TRACE = STACK_TRACE.Replace(Environment.NewLine, "<br>");

于 2013-03-20T18:13:45.837 に答える
0

たとえば、C# コードでは次のようになります。

string str = "TEXT TEXT TEXT\n, TEXT TEXT\t TEXT. TEXT TEXT\n\t TEXT TEXT.";
str = str.Replace("\n", "<br/>").Replace("\t", "<br/></br>");

結果:

**TEXT TEXT TEXT<br/>, TEXT TEXT<br/></br> TEXT. TEXT TEXT<br/><br/></br>TEXT TEXT.**

一連の置換を書くことができます。

JavaScript で置換する場合は、RegExp を使用します。この記事を見る

于 2013-03-20T18:55:39.390 に答える