找到一个字符串EX pression在一个句子 [英] finding an string expression in an sentence

查看:158
本文介绍了找到一个字符串EX pression在一个句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样三个词的前pression:关上了门,我想找到它在一个句子里。因为它们是一种由分隔空间,这将是它的最佳解决方案。

I have like a three word expression: "Shut The Door" and I want to find it in a sentence. Since They are kind of seperated by space what would be the best solution for it.

推荐答案

如果您有字符串:

string sample = "If you know what's good for you, you'll shut the door!";

和你想找到的地方是在一个句子中,可以使用IndexOf方法。

And you want to find where it is in a sentence, you can use the IndexOf method.

int index = sample.IndexOf("shut the door");
// index will be 42

一个非-1的回答表示字符串已经定位。 -1意味着它不字符串中存在。请注意,搜索字符串(关上了门)是区分大小写的。

A non -1 answer means the string has been located. -1 means it does not exist in the string. Please note that the search string ("shut the door") is case sensitive.

这篇关于找到一个字符串EX pression在一个句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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