如何获取字符串中单词的INDEX [英] How to get INDEX of word inside a string
本文介绍了如何获取字符串中单词的INDEX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取字符串中单词的索引,并且如果可能的话,还删除字符串中该单词之前的所有字符,这将使我的生活更轻松。
I am trying to get the INDEX of a word inside a string and if possible also to delete all the characters previous to this word in the string, it would make my life easier.
有人可以帮助我吗?我在c#
Could anyone help me? Im doing this on c#
推荐答案
上执行此操作,您将要对字符串使用IndexOf函数。这将告诉您所要查找的单词,字符等的起始字符位置。
You'll want to use the IndexOf function on a string. This will tell you the starting character position of the word, character, etc that you're looking for.
以下是示例控制台应用程序:
Here is an example console app:
static void Main(string[] args)
{
String testing = "text that i am looking for";
Console.Write(testing.IndexOf("looking") + Environment.NewLine);
Console.WriteLine(testing.Substring(testing.IndexOf("looking")));
Console.ReadKey();
}
这将输出:
15
寻找
This will output:
15
looking for
这篇关于如何获取字符串中单词的INDEX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文