ttbs123 发表于 2007-10-3 17:42:55

搜索了大半天,还是没有结果,只好发问麻烦大家了。

请问一个字符串,例如"abcde;fghijk"
我要获取fghijk,应该以;为分隔符
但是没有类似mid或者split的函数,我无从入手,请问要用什么函数呢??

Rulzy 发表于 2007-10-3 20:44:36

回复: 搜索了大半天,还是没有结果,只好发问麻烦大家了。

contain(const source[], const string[]) - Returns position of string found inside of source, or -1 on failure(返回string在source中找到的位置,失败返回-1).

containi(const source[], const string[]) - Returns position of string found inside of source, or -1 on failure. Case insensitive(返回string在source中找到的位置,失败返回-1。不区别大小写).

Rulzy 发表于 2007-10-3 20:51:10

回复: 搜索了大半天,还是没有结果,只好发问麻烦大家了。

parse (const text[], str1[], maxlen1, ... )- Splits parameters into strings(分解字符串,以空格来分隔,但用引号引起来的是一个子串).

strbreak ( const text[], left[], leftLen, right[], rightLen ) - Gets parameters from text one at a time(这个也可以分解字符串,不过只分别为两部分,后部分可以再用strbreak分解).

ttbs123 发表于 2007-10-3 23:35:45

回复: 搜索了大半天,还是没有结果,只好发问麻烦大家了。

谢谢rulzy大哥,刚才已经自己解决了,我用containi获取字符串位置,接着用copy截取后面部分,自用replace替换掉不要的字符,得到了我想要的字符串。
本来想用parse的,但字符串分隔的不是空格,strbreak也是,因为不知道到底要去左边或者右边多少。

同时我在国外论坛找到这个函数,处理这种字符串更加快捷,希望对需要的朋友有用。
stock explode( output[][], input[], delimiter, textlen, maxMatches )
{
      new nIdx = 0
      new nLen = (1 + copyc( output, textlen, input, delimiter ))
      new len = strlen(input)
      while( nLen < len && nIdx < maxMatches )
      nLen += (1 + copyc( output[++nIdx], textlen, input, delimiter ))
}
new newstring;
new oldstring;
oldstring = "123.456.789.000";
explode(newstring, oldstring, '.', 31, 4);

ttbs123 发表于 2007-10-3 23:38:19

回复: 搜索了大半天,还是没有结果,只好发问麻烦大家了。

昨晚去rulzy大哥的服务器玩了一下,需要下载好多东西才能进入啊。

Ryu2877 发表于 2007-10-7 21:51:02

回复: 搜索了大半天,还是没有结果,只好发问麻烦大家了。

这种功能AMXX有现成的函数:

strtok


Syntax:

   strtok ( const text[], Left[], leftLen, Right[], rightLen, token=' ', trimSpaces=0 )
Type:

    Native
Notes:

Breaks a string into two halves, by token. See strbreak for doing this with parameters.

Example:

str1[] = "This *is*some text"
strtok(str1, left, 24, right, 24, '*')

left will be "This "
Right will be "is*some text"

If you use trimSpaces, all spaces are trimmed from Left.



只是该函数平时少人用,具体例子可以看:

http://forums.alliedmods.net/showthread.php?t=47318

源码.
页: [1]
查看完整版本: 搜索了大半天,还是没有结果,只好发问麻烦大家了。