如何提取以'abc'开头的字符串&以'xyz'结尾? [英] How to extract a string starting with 'abc' & ending with 'xyz' ?
问题描述
我想从文本文件中提取字符串abc * xyz。
*表示任意编号。人物。
当字符串确定没有时,我才能做到。字符
或字符串长度是常数:即五或字符串是abc ?????
xyz
如何概括它对于任何长度的字符串?
I want to extract a string abc*xyz from a text file.
* indicates arbitrary no. of characters.
I''m only able to do it when the string has definite no. of characters
or the string length is constant: i.e. five or the string is abc?????
xyz
How can i generalize it for any length of the string?
推荐答案
Umesh写道:
Umesh wrote:
我想从文本文件中提取字符串abc * xyz。
*表示任意编号。人物。
当字符串确定没有时,我才能做到。字符
或字符串长度是常数:即五或字符串是abc ?????
xyz
如何概括它对于任何长度的字符串?
I want to extract a string abc*xyz from a text file.
* indicates arbitrary no. of characters.
I''m only able to do it when the string has definite no. of characters
or the string length is constant: i.e. five or the string is abc?????
xyz
How can i generalize it for any length of the string?
你有没有查找正则表达式?
-
Ian Collins。
Have you looked up regular expressions yet?
--
Ian Collins.
" Umesh" < fr **************** @ gmail.comschrieb im Newsbeitrag
news:11 ************** *******@g37g2000prf.googlegro ups.com ...
"Umesh" <fr****************@gmail.comschrieb im Newsbeitrag
news:11*********************@g37g2000prf.googlegro ups.com...
>我想从文本文件中提取字符串abc * xyz。
*表示任意编号。人物。
当字符串确定没有时,我才能做到。字符
或字符串长度是常数:即五或字符串是abc ?????
xyz
如何概括它对于任何长度的字符串?
>I want to extract a string abc*xyz from a text file.
* indicates arbitrary no. of characters.
I''m only able to do it when the string has definite no. of characters
or the string length is constant: i.e. five or the string is abc?????
xyz
How can i generalize it for any length of the string?
您可能想要查找正则表达式的正则表达式。
http://directory.fsf.org/regex.html
再见,Jojo
You may want to look for regex, a librarx for regular expressions.
http://directory.fsf.org/regex.html
Bye, Jojo
" Umesh" < fr **************** @ gmail.com写信息
新闻:11 ************** *******@g37g2000prf.googlegro ups.com ...
"Umesh" <fr****************@gmail.comwrote in message
news:11*********************@g37g2000prf.googlegro ups.com...
>我想从文本文件中提取字符串abc * xyz。
*表示任意编号。人物。
当字符串确定没有时,我才能做到。字符
或字符串长度是常数:即五或字符串是abc ?????
xyz
如何概括它对于任何长度的字符串?
>I want to extract a string abc*xyz from a text file.
* indicates arbitrary no. of characters.
I''m only able to do it when the string has definite no. of characters
or the string length is constant: i.e. five or the string is abc?????
xyz
How can i generalize it for any length of the string?
正如其他人所指出的那样,如果你想处理
的一般性问题如何我可以将字符串与特征字符串匹配,例如你想要
正则表达式。
然而对于一次性的简单模式,正则表达式是矫枉过正的。
使用strncmp()来将前三个字符与abc进行比较。调用strlen()
来找到字符串的结尾,向后移动三个位置(确保你不要将b $ b移入你不拥有的记忆中,减去一个),调用strcmp()和
" xyz" ;.
在它自己的一个小功能中扭曲它>
-
免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm
As others have pointed out, if you want to handle the geneneral problem of
"how can I match a string with charcteristics such and such" you want
regular expressions.
However for a one off simple pattern regular expressions are overkill.
Use strncmp() to compare the first three character to "abc". Call strlen()
to find the end of the string, move back three places (make sure you don''t
move into memory you don''t own, place minus one), the call strcmp() with
"xyz".
Warp it all up in a little function of its own
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
这篇关于如何提取以'abc'开头的字符串&以'xyz'结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!