【发布时间】:2012-10-25 08:42:51
【问题描述】:
我有一条消息,长度为 287 个字符。我需要在 160 个字符后将其分成两部分,但我的代码仍然无法正常工作。我用谷歌搜索了很多,尝试了很多不同的解决方案,但没有什么能像我预期的那样工作。在我看来,这是一个简单的解决方案,但在实践中却让我做噩梦!
// a check is done to ensure the message is > 160 in length.
string _message;
_message = "this is my long message which needs to be split in to two string after 160 characters. This is a long message. This is a long message. This is a long message. This is a long message. This is a long message.";
string message1 = _message.Substring(0,160);
string message2 = _message.Substring(161,_message.Length);
上述方法根本不起作用 - 在第二个子字符串上给我一个异常错误。
有人可以帮忙吗?消息永远不会超过 320 个字符。
【问题讨论】: