CAPL脚本常用字符串函数 |
您所在的位置:网站首页 › string赋值给字符数组 › CAPL脚本常用字符串函数 |
Capl中字符串处理API
strlen()strncat()strncmp()strncpy()strstr()str_replace()substr_cpy()swapWord()toLower()toUpper()
Capl中字符串处理API
strlen()
字符串的长度 输出: strlen:9 elCount:100 strncat()将源字符串拼接到到目的字符串后面,注意“\0”也占用一个字节。 输出: s1:s2 = -1 s1:s3 = -1 s1:s4 = 1 s1:s5 = 0 函数的机制是:逐个字符比较,遇见不同的字符,比较其ASCII值,然后返回值。 long strncmp_off(char s1[], long s1offset, char s2[], long s2offset, long len); 相比strncmp ,strncmp_off 多了个offset参数 输出: s1:s2 = 0 strncpy()把源字符串拷贝到目的字符串数组,拷贝长度由len参数决定,拷贝过程会覆盖目的字符串数组原来内容。 输出: s1 = 789 s1 = void strncpy_off(char dest[], long destOffset, char src[], long max); 相当于 strncpy 和 strncat 的结合 输出: pos:6 pos:2 long strstr_off(char s1[], long offset, char s2[]); 规定被搜索的字符串数组位置。 On key 'c' { long pos,i; char s1[18] = "hello world"; char s2[11] = "world"; for(i=0;i long pos,i; char s1[18] = "12121212"; char s2[11] = "world"; str_replace(s1, "1", "3"); write("s1:%s",s1); }输出: s1:32323232 long str_replace(char s[], long startoffset, char replacement[], long length); // form 2 用另一个字符串替代被搜索的字符串的一部分,注意期望的结果字符串数组大小不能大于被搜索的字符串数组 On key 'c' { long pos,i; char s1[18] = "12345678"; str_replace(s1,4, "asdfg",strlen(s1));//form2 ,从索引4后面的字符串被"asdfg"替代 write("s1:%s",s1); }输出: s1:1234asdfg substr_cpy()拷贝源字符串的子字符串到目的字符串 输出: Word:3412 int:3412 dword :78563412 long :78563412 int64 :4365879078563412 qword :4365879078563412 toLower()将输入字符或者字符串转换成小写 输出: s :a s :asdfgh toUpper()将输入字符或者字符串转换成大写,用法参考 toLower |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |