代码之家  ›  专栏  ›  技术社区  ›  Kurru

在c中使用此字符串值的最佳方式是什么?

  •  0
  • Kurru  · 技术社区  · 14 年前

    使下面的HTML文本块成为c#中的硬编码字符串对象的最佳方法是什么?我需要一个测试不能使用@运算符,因为它只是在第一个停止。有什么想法吗?

    ====================================================

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <HTML>
    
    <HEAD>
    
      <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    
      <TITLE>Example Web Page</TITLE>
    
    </HEAD> 
    
    <body>  
    
    <p>You have reached this web page by typing &quot;example.com&quot;,
    
    &quot;example.net&quot;,&quot;example.org&quot
    
      or &quot;example.edu&quot; into your web browser.</p>
    
    <p>These domain names are reserved for use in documentation and are not available 
    
      for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC 
    
      2606</a>, Section 3.</p>
    
    </BODY>
    
    </HTML>
    
    4 回复  |  直到 14 年前
        1
  •  6
  •   David Mårtensson    14 年前

    您可以使用@,但必须避开任何“as”(双精度)

    据我所知,没有别的办法了。

    第一行是

    @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">
    
    <HTML>
    
        2
  •  5
  •   Jon Skeet    14 年前

    我建议您将其放在文本文件中,然后嵌入到程序集中。这样你就可以用语法高亮等方式编辑它,而且不会把你的代码弄乱。

    使用 Assembly.GetManifestResourceStream 在执行时再次加载。如果这样做的数量相当大,您可能希望编写帮助器方法来更轻松地完成此任务。

        3
  •  1
  •   Nobody    14 年前

    如果你不想像Jon Skeet的答案那样嵌入它,你必须改变 " "" .

        4
  •  0
  •   RKh    14 年前

    也许这个链接可以回答您的问题:

    Storing HTML tags in a string variable.