【问题标题】:How to read in C# the Newline character in a SQLite database?如何在 C# 中读取 SQLite 数据库中的换行符?
【发布时间】:2015-03-29 17:48:20
【问题描述】:

我目前正在开发的应用程序需要检索存储在SQLite DB 中的TEXT 字段中的Newline (\n) 字符。 SQLite 中\n 对应的字符是什么? 因为

string[] words = str.Split(new string[] { @"\r\n" }, StringSplitOptions.None);

好像没用。

【问题讨论】:

  • \r\n - 这是 Windows 的通用解决方案。 MAC 是\r,Unix 是\n。尝试所有这些,然后删除@

标签: c# sqlite newline


【解决方案1】:
string[] words = str.Split(new string[] { "\r\n" }, StringSplitOptions.None);

""之前不要@,否则表示\r\n...或者试试

string[] words = str.Split(new string[] { "\n" }, StringSplitOptions.None);

取决于程序保存在数据库中的内容。

现在,如果你真的想确保抓住任何东西,你可以......

string[] words = str.Split(new[] { "\r\n", "\r", "\n", StringSplitOptions.None);

@means

逐字字符串文字由一个 @ 字符后跟一个 双引号字符,零个或多个字符,以及一个结束 双引号字符。一个简单的例子是@"hello"。逐字逐句 字符串文字,分隔符之间的字符被解释 逐字逐句,唯一的例外是引号转义序列。在 特别是,简单的转义序列和十六进制和 Unicode 转义序列不会在逐字字符串文字中处理。一种 逐字字符串文字可能跨越多行。

【讨论】:

    【解决方案2】:

    您始终可以使用 Environment.NewLine。

    // Summary:
    //     Gets the newline string defined for this environment.
    //
    // Returns:
    //     A string containing "\r\n" for non-Unix platforms, or a string containing
    //     "\n" for Unix platforms.
       public static string NewLine { get; }
    
    
    string[] words = str.Split(new[] { Environment.NewLine} , StringSplitOptions.None);
    

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 2012-12-05
      • 2022-11-26
      相关资源
      最近更新 更多