0

例如我有这个字符串:顺便说一句,这是一个评论“哈哈哈”

BTW 是一个注释运算符,它后面的所有语句都被忽略。我需要将 BTW 作为 'comment_operator' 和 'This is a comment'hahaha'' 作为 datagridview 中的'comment'。

但我不能这样做,因为我在代码中使用空格作为分隔符,所以“这是一个注释“哈哈哈”也将被连接,但我需要它。

有人可以启发我吗?谢谢。

4

1 回答 1

1

我假设您希望第一次出现空格时需要单独的 2 个部分。您可以使用以下代码:

string text = @"BTW This is a comment ""hahaha""";
string comment_operator = text.Substring(0, text.IndexOf(' '));
string comment = text.Substring(comment_operator.Length + 1);
于 2013-10-13T11:27:00.677 回答