修剪/删除字符串中的制表符("\ t") [英] Trim / remove a tab ( "\t" ) from a string

查看:72
本文介绍了修剪/删除字符串中的制表符("\ t")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议从字符串中删除制表符("\ t" s)的方法吗?CString或std :: string.

Can anyone suggest a way of stripping tab characters ( "\t"s ) from a string? CString or std::string.

因此,"1E10     "例如变为"1E10".

So that "1E10      " for example becomes "1E10".

推荐答案

std :: remove() 来自< algorithm> 实际上并没有使字符串更短-它只是返回一个迭代器,说新序列将在此处结束".您需要调用 my_string().erase()为此:

hackingwords' answer gets you halfway there. But std::remove() from <algorithm> doesn't actually make the string any shorter -- it just returns an iterator saying "the new sequence would end here." You need to call my_string().erase() to do that:

#include <string>
#include <algorithm>    // For std::remove()

my_str.erase(std::remove(my_str.begin(), my_str.end(), '\t'), my_str.end());

这篇关于修剪/删除字符串中的制表符("\ t")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆