c /c ++库strxfrm()将源字符串的字符转换为当前语言环境,并将其放置在目标字符串中。对于该LC_COLLATE类别,该类别在locale.h中定义。 strxfrm()函数执行转换的方式是,两个字符串上的strcmp结果与两个原始字符串上的strcoll结果相同。句法:
size_t strxfrm(char *str1, const char *str2, size_t num); parameters: str1:is the string which receives num characters of transformed string. str2:is the string which is to be transformed num :is the maximum number of characters which to be copied into str1.
例子:
Input:'geeksforgeeks' Output:13
// C program to demonstrate
// strxfrm()
#include <stdio.h>
#include <string.h>
int main()
{
char src[10], dest[10];
int len;
strcpy(src, "geeksforgeeks");
len = strxfrm(dest, src, 10);
printf("Length of string %s is:%d", dest, len);
return (0);
}
输出:
Length of string geeksforgeeks is:13
范例2:
Input:'hello geeksforgeeks' Output:20 // in this example it count space also
// C program to demonstrate
// strxfrm()
#include <stdio.h>
#include <string.h>
int main()
{
char src[20], dest[200];
int len;
strcpy(src, " hello geeksforgeeks");
len = strxfrm(dest, src, 20);
printf("Length of string %s is:%d", dest, len);
return (0);
}
输出:
Length of string hello geeksforgeeks is:20
范例3:
// C program to demonstrate
// strxfrm()
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char str2[30] = "Hello geeksforgeeks";
char str1[30];
cout << strxfrm(str1, str2, 4) << endl;
cout << str1 << endl;
cout << str2 << endl;
return 0;
}
输出:
19 Hell Hello geeksforgeeks
相关用法
注:本文由纯净天空筛选整理自 strxfrm() in C/C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。