What about string cutting functions?

Source: Internet
Author: User
Tags strtok

刚开始学习JScript,实在无聊透顶,写了几行代码。就碰上一个问题:关于字符串切割的

记得之前写C时候,花费了很大一段时间去分析这个strtok函数。

首先说一下strtok这个

头文件:#include <string.h>
定义函数:char * strtok(char *s, const char *delim);

参数2是一个字符串,具体的是根据字符串中每一个字符来分割的。

看例子

#include <string.h>

main()

{

  char s[] = "ab-cd : ef;gh :i-jkl;mnop;qrs-tu: vwx-y;z";

  char *delim = "-: ";

  char *p;

  printf("%s ", strtok(s, delim));

  while((p = strtok(NULL, delim)))

    printf("%s ", p);

  printf("\n");

}

输出:ab cd ef;gh i jkl;mnop;qrs tu vwx y;z

显然是根据delim字符串中每个字符来做切割的。

然后是JScript中的split

stringObj.split( [separator[, limit]])

separator是一个整体的

 

字符串切割函数那些事儿

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.