Declaring a looooong single line string in C#

后端 未结 11 1008
礼貌的吻别
礼貌的吻别 2021-02-05 00:58

Is there a decent way to declare a long single line string in C#, such that it isn\'t impossible to declare and/or view the string in an editor?

The options I\'m aware o

11条回答
  •  野的像风
    2021-02-05 01:43

    If you really want this long string in the code, and you really don't want to type the end-quote-plus-begin-quote, then you can try something like this.

    string longString = @"Some long string, 
        with multiple whitespace characters 
        (including newlines and carriage returns)
        converted to a single space
        by a regular expression replace.";
    
    longString = Regex.Replace(longString, @"\s+", " ");
    

提交回复
热议问题