从字符串(char *)删除空格尾 [英] remove whitespaces tail from string (char*)
本文介绍了从字符串(char *)删除空格尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有带行格式的文本文件
hello I've got text file with lines format
1|few ewf ew fewfew
我需要解析它,但是我不知道如何从我不知道的第二个值中删除空格尾.
I need to parse it but I don't know how can I drop whitespaces tail from second value I don't know.
这是我到目前为止的segmentation fault
尝试
Here is my segmentation fault
try so far
char* token1;
char* token2;
char* search = "|";
char* search2 = " "; // double space because string can contains single space
while (fgets(line, 150, f)) {
token1 = strtok(line, search);
token2 = strtok(search, search2); // <- segfault
//token2 = strtok(NULL, search); <- contains a lot of spaces in tail
推荐答案
使用deblank
函数.这是链接: http://www.mathworks.com/help/matlab/ref /deblank.html
Take a gander at the deblank
function. Here's a link: http://www.mathworks.com/help/matlab/ref/deblank.html
这篇关于从字符串(char *)删除空格尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文