[英]Removing First and Last Character from string array
Hello im trying to find a way to remove the first and last character of an array of strings.你好我试图找到一种方法来删除字符串数组的第一个和最后一个字符。
My data insight the array is something like this:我的数据洞察数组是这样的:
"Time1": “时间1”:
"3.0" “3.0”
etc.等等
Im trying specifically to remove the double quotes and the char: What should i use?我试图专门删除双引号和字符:我应该使用什么?
char item[100];
char LastArray[1000];
while (NewMixedArray[i] != NULL)
{
sscanf (NewMixedArray[i],"\"%99[^\"]", item);
LastArray[i]=item;
printf("%d %s\n",i,LastArray[i]);
i++;
}
i=0;
while ( LastArray[i] != NULL)
{
printf("DONE: %d %s\n",i,LastArray[i]);
i++;
}
On the second printf im getting only the last value.在第二个 printf 上,我只得到最后一个值。
https://i.imgur.com/H2OFz1Q.png https://i.imgur.com/H2OFz1Q.png
I found my problem i used the command我发现我的问题我使用了命令
LastArray[i] = strdup(item); LastArray[i] = strdup(item); Because my LastArray was an array of pointers.因为我的 LastArray 是一个指针数组。
#include <stdio.h>
#include <string.h>
int main() {
char string[1000], result[1000];
strcpy(string, "\"Time1\":");
printf("\nInitial String : %s", string);
int i;
int c = 0;
do {
if (string[i] != '\"' & string[i] != ':') {
result[c] = string[i];
c++;
}
i++;
} while (string[i] != '\0');
printf("\nResult : %s\n", result);
return 0;
}
Result结果
$ ./ss
Initial String : "Time1":
Result : Time1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.