在特定单词后面取文字 [英] Take text after a specific word

查看:95
本文介绍了在特定单词后面取文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


所以基本上我需要的是当用户输入如下命令时:kill player我需要的是只接受玩家名字而不包含的字符串"杀" ;.我看过论坛并尝试了不同的东西,但只有当
只是"杀死"时它似乎才有效。没有球员的名字。如果在"杀死"之后有一个玩家名字它不会删除"杀死"。有任何想法吗?谢谢! 

解决方案

嗨Frasski,


欢迎来到MSDN论坛。


您的项目类型是什么?


请参阅说明,请检查

这个类似的问题
在特定单词之后得到一个字符串。


我们ca n使用以下方法:


字符串
toBeSearched =
"代码:" ;


字符串
code = myString。
子串 (myString。 IndexOf (toBeSearched)
+ toBeSearched。
Length );




字符串
ErrorCode
= yourString。
分割
string [] { " code" },
StringSplitOptions )。 最后 ();



我试图创建一个简单的C#控制台应用程序来测试它,它工作正常如下:


< img alt =""src ="https://social.msdn.microsoft.com/Forums/getfile/1393652">




最好的问候,


萨拉


Hello,

So basically what I need is when the user enters a command like: kill player What I need is the string to only take the player name and not include "kill". I've looked in forums and tried out different things but it only seems to work when there's just "kill" with no player name. If there's a player name after "kill" it doesn't remove "kill". Any ideas? Thanks! 

解决方案

Hi Frasski,

Welcome to the MSDN forum.

What is your project type?

Refer to the description, please check this similar issue to get a string after the specific word.

We can use the following methods:

string toBeSearched = "code : ";

string code = myString.Substring(myString.IndexOf(toBeSearched) + toBeSearched.Length);

Or

string ErrorCode = yourString.Split(new string[]{"code"}, StringSplitOptions.None).Last();

I tried to create a simple C# console application to test it and it works fine as below:

Best regards,

Sara


这篇关于在特定单词后面取文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆