Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用字符串开头的字符数拆分字符串?_C#_String_Split - Fatal编程技术网

C# 如何使用字符串开头的字符数拆分字符串?

C# 如何使用字符串开头的字符数拆分字符串?,c#,string,split,C#,String,Split,如何使用字符串开头的字符数拆分字符串 这是我的密码: string website; if (message.Contains("!help")) { SendChatMessage("\n!resolve <url> - Resolve a website URL\n!spam <steamID> <message> - Spam a steam user\n!help - View commands list"); } else if (mess

如何使用字符串开头的字符数拆分字符串

这是我的密码:

string website;

if (message.Contains("!help"))
{
    SendChatMessage("\n!resolve <url> - Resolve a website URL\n!spam <steamID> <message> - Spam a steam user\n!help - View commands list");
}
else if (message.Contains("!resolve"))
{
    website = message;
    SendChatMessage(website);
    SendChatMessage("Resolving...");
    SendChatMessage("I couldn't resolve that IP address! Sorry!");
}

这是杂乱无章的,格式也很糟糕,但我是C语言的新手,我想知道是否有任何方法可以利用最初的8个字符来拆分网站字符串:!解析之后将有一个网站url。

拆分基于字符或字符串。如果要按位置拆分,则需要子字符串:

dotnetperls有一个更为用户友好的解释: 使用是最快捷、最简单的方法

var text = "!resolve http://www.google.com";
var url = text.Substring(8).Trim();

Substring的第一个参数是从零开始复制到字符串中的索引。如果您只指定该参数,它将把从该索引开始的字符串中的所有文本复制到一个新字符串中。

您可以使用-这将使所有内容从索引8开始,即第9个字符。您可能需要使用message.StartsWith!改为解决。谢谢你修复了它!非常感谢。我甚至不完全理解那里发生了什么,有人有我可以学习子字符串函数的资源吗?Sam使用microsoft资源的回复很难理解lol中的大量技术术语。再次感谢!