通过一个字符串对指定的字符串进行分割

列如split(char* arc,char a,int i)对arc通过指定的a进行分割,然后再根据i来输出分割后的字符串
arc=“ddd bbbb vvvv nnn”然后a是一个空格,然后i是2,则输出bbbb,要是i是3则输出vvvv,求大神代码附上好好讲解一下

如果是 Windows 平台,可以参考如下代码:

 #include <string.h>
#include <stdio.h>

char string[] = "A string\tof ,,tokens\nand some  more tokens";
char seps[]   = " ,\t\n";
char *token;

void main( void )
{
   printf( "%s\n\nTokens:\n", string );
   /* Establish string and get the first token: */
   token = strtok( string, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      printf( " %s\n", token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }
}
Output
A string   of ,,tokens
and some  more tokens

Tokens:
 A
 string
 of
 tokens
 and
 some
 more
 tokens

有一个split 方法将字符串按照指定字符分割,返回一个字符串数组,应该能满足你的要求

 var s = "ddd bbbb vvvv nnn";

var sp = function(arc, a, i){
  var temp = s.split(a);

  if(temp[i]){
    return temp[i]
  }else{
    return s
  }
}

sp(s," ",1)

http://download.csdn.net/download/zhougan0816/5749259

arc.split(' ')[i]