如何获取字符串中单词的INDEX

编程入门 行业动态 更新时间:2024-10-10 01:27:03
本文介绍了如何获取字符串中单词的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: 15looking for

更多推荐

如何获取字符串中单词的INDEX

本文发布于:2023-11-30 12:33:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   单词   INDEX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!