簡體   English   中英

從字符串c ++的開頭和結尾刪除標點符號

[英]Remove punctuation from beginning and end of string c++

有沒有辦法特別從字符串的開頭和結尾刪除標點符號,同時單獨留下收縮和占有欲?

例如“!哇!” 會變成“哇”而“不能”會留下“不能”

你可以用boost::trim_if做到這boost::trim_if

std::string a = "!wow!";
boost::trim_if(a, [](char c) { return std::ispunct(c); });
std::cout << a << '\n';

輸出:

wow

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM