获取子指数 [英] Get index of substring
本文介绍了获取子指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的的char *源,我想从中提取subsrting,我知道是从符号ABC开始,结束其中source结束。随着的strstr 我能得到poiner,但没有位置,没有位置,我不知道该串的长度。我怎样才能获得字符串的索引纯C?
I have char * source, and I want extract from it subsrting, that I know is beginning from symbols "abc", and ends where source ends. With strstr I can get the poiner, but not the position, and without position I don't know the length of the substring. How can I get the index of the substring in pure C?
推荐答案
使用指针减法。
char *str = "sdfadabcGGGGGGGGG";
char *result = strstr(str, "abc");
int position = result - str;
int substringLength = strlen(str) - position;
这篇关于获取子指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文