社区
C++ 语言
帖子详情
indexof
mingzaili
2010-01-05 11:18:07
在c#中有IndexOf可以对一个字符串查找.
如"abcde".IndexOf("cd")将返回2.
请问在c++中如何完成类似的功能呢?
...全文
94
11
打赏
收藏
indexof
在c#中有IndexOf可以对一个字符串查找. 如"abcde".IndexOf("cd")将返回2. 请问在c++中如何完成类似的功能呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
鼠
2010-01-05
打赏
举报
回复
string("abcde").find("cd")
mingzaili
2010-01-05
打赏
举报
回复
那具体怎么写呢?
我刚刚接触到c++,一头雾水. 公司有个小程序要用c++写,有点急.
谢啦!!
macrojj
2010-01-05
打赏
举报
回复
find吧
find_first_of
等等
healer_kx
2010-01-05
打赏
举报
回复
[Quote=引用 4 楼 freezezdj 的回复:]
string str = "abcde";
str.find("cd");
C++ 不支持 “abced”.find("cd"); 这种语法。
[/Quote]
那是因为C++编译器不会把 字符串字面量 处理为对象,而且也没有一个真正意义上的字符串对象。。。
pengzhixi
2010-01-05
打赏
举报
回复
string中的find函数
size_t find ( const string& str, size_t pos = 0 ) const;
size_t find ( const char* s, size_t pos, size_t n ) const;
size_t find ( const char* s, size_t pos = 0 ) const;
size_t find ( char c, size_t pos = 0 ) const;
pengzhixi
2010-01-05
打赏
举报
回复
string中的find函数
size_t find ( const string& str, size_t pos = 0 ) const;
size_t find ( const char* s, size_t pos, size_t n ) const;
size_t find ( const char* s, size_t pos = 0 ) const;
size_t find ( char c, size_t pos = 0 ) const;
pengzhixi
2010-01-05
打赏
举报
回复
string中的find函数
size_t find ( const string& str, size_t pos = 0 ) const;
size_t find ( const char* s, size_t pos, size_t n ) const;
size_t find ( const char* s, size_t pos = 0 ) const;
size_t find ( char c, size_t pos = 0 ) const;
冻结
2010-01-05
打赏
举报
回复
string str = "abcde";
str.find("cd");
C++ 不支持 “abced”.find("cd"); 这种语法。
pengzhixi
2010-01-05
打赏
举报
回复
string中的find函数
healer_kx
2010-01-05
打赏
举报
回复
find... ...
wanjiwz
2010-01-05
打赏
举报
回复
[Quote=引用楼主 mingzaili 的回复:]
在c#中有IndexOf可以对一个字符串查找.
如"abcde".IndexOf("cd")将返回2.
请问在c++中如何完成类似的功能呢?
[/Quote]
strstr()函数可以返回指向子串首地址的指针,然后可以计算出偏移量来
基于ArcGIS的Arcpy编程(通俗易懂)
自定义脚本工具设置参数arcpy.etParamaterAsText(index)、arcpy.etParamatert(index)、 通过脚本创建要素类arcpy.CreateFeatureClasses_management() 按照属性选择要素arcpy.SelectFeatureClassByAttribute 按照位置...
Java中字符串
indexof
() 的使用方法
Java中字符串中子串的查找共有四种方法(
indexof
())
indexOf
方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回-1。 如果 startindex 是负数,则 startindex 被当作零。如果它比最大的字符位置索引还大,则它被当作最大的可能索引。 Java中字符串中子串的查找共有四种方法,如下: 1、int
indexOf
(S...
js的
indexOf
方法
一、数组调用
indexOf
() 方法可返回数组中某个指定的元素位置。 该方法将从头到尾地检索数组,看它是否含有对应的元素。开始检索的位置在数组 start 处或数组的开头(没有指定 start参数时)。如果找到一个 item,则返回 item 的第一次出现的位置。开始位置的索引为 0。 如果在数组中没找到指定元素则返回 -1。 //语法 // array.
indexOf
(item,start) //item 必须 要查找的元素的位置, //start 非必须可选的整数参数。
详解java中的
indexOf
()方法
详解java中的
indexOf
()方法 介绍一下
indexOf
()的两种用法和实现功能: 1、
indexOf
(String str): 返回指定字符str在字符串中(方法调用者)第一次出现处的起始索引,如果此字符串中没有这样的字符,则返回 -1。 2、
indexOf
(String str, int index): 返回从 index 位置开始查找指定字符str在字符串中第一次出现处的起始索引,如...
String.
indexOf
()的四种方法
String.
indexOf
()的四种方法 String.
indexOf
(String str) 官方解释 : 返回此字符串中第一次出现指定子字符串的索引。返回的索引是最小值k ,其中: this.startsWith(str, k)如果不存在这样的k值,则返回-1 。 参数: str – 要搜索的子字符串。 返回: 指定子字符串第一次出现的索引,如果没有这样的出现,则为-1 。 public int
indexOf
(String str) { return
indexOf
(str, 0);
C++ 语言
64,649
社区成员
250,477
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章