關於boost裡面的string

2022-04-05 17:32:58 字數 2969 閱讀 7283

#include

首先是盤點子串是否是父串的乙個子串。

如下所示:

std::string str("

i don't know.\n");

std::cout

<<:to_upper_copy>

std::cout

<

boost::to_lower(str);

std::cout

<

std::

string str("

power bomb");

if (boost::iends_with(str, "

bomb"))

if (!boost::ends_with(str, "

bomb"))

std::cout

<< "

no bomb\n";

if (boost::starts_with(str, "

pow"

)) std::cout

<< "

start pow

"<<:endl>

if (boost::contains(str, "er"

)) std::cout

<< "

contains er\n";

std::

string str2 =boost::to_lower_copy(str);

if(boost::iequals(str, str2))

std::cout

<< "

iequal

"<<:endl>

std::

string str3("

power suit");

if(boost::lexicographical_compare(str, str3))

if (boost::all(str2.substr(0, 5

), boost::is_lower()))

std::cout

<< "

is low

"<< std::endl;

view code

在這裡有各種的查詢和判斷是否相等,如果前面加i說明是沒有計較大小寫。

還有乙個很長的函式lexicographical_compare,該函式是判斷左邊的字串是否小於右邊的字串。

boost::all(str2.substr(0, 5), boost::is_lower())

這個是判斷all函式的第乙個引數是否全部是小寫的,如果是返回true

接下去是這個去除字串頭尾指定的字元的trim函式。如果不寫if則預設是刪除空格。如果有if責判斷去除特定的字元。也可以刪除多個特定的字元。如:boost::trim_copy_if(str2, boost::is_punct()||boost::is_digit())  去除符號和數字,並通過拷貝返回去,對str2不做改變。

對於erase和replace這兩個函式也是差不多的道理,

std::cout << boost::ierase_all_copy(str, "samus");

std::cout << boost::replace_nth_copy(str, "l", 1, "l");

std::cout << boost::erase_tail_copy(str, 8);

接下來這個是關於分割的各種方式

加#include

std::string str = "

samus,link.zelda::mario-luigi+zelda";

std::deque

string>d;

boost::ifind_all(d, str,

"zelda");

for (boost_auto(pos, d.begin()); pos != d.end(); ++pos)

std::cout

<<:endl>

std::list

string::iterator> >l;

boost::split(l, str, boost::is_any_of(

",.:-+

"));

for (boost_auto(pos, l.begin()); pos != l.end(); ++pos)

std::cout

<<:endl>

l.clear();

boost::split(l, str, boost::is_any_of(

".:-

"), boost::token_compress_on);

for (boost_auto(pos, l.begin()); pos != l.end(); ++pos)

std::cout

<< std::endl;

view code

在分割的時候可以有多個字元來做個分隔符。並把分割後的字串儲存到乙個容器中。如上面**所示。

這裡要提的乙個是:boost::token_compress_on   使能壓縮和另乙個boost::token_compress_off的使能不壓縮即在兩個分隔符連在一起的時候如果使能壓縮,則只看成是乙個分隔符。

有分割就有合併

std::vectorstring> v = boost::assign::list_of("

samus

")("

link

")("

zelda

")("

mario");

std::cout

<< boost::join(v, "

+") <<:endl>

struct

is_contains_a

};std::cout

<< boost::join_if(v, "

**", is_contains_a());

view code

關於channel裡面的策略

關於channel裡面的策略 channel裡面的配置主要在data.data 0 pyload.data.config裡面。config是由groups遞迴形成的。groups的結構如下 groups 下一層 mod policy 當前層發生改變時,需要執行的策略名稱 policies 當前層策略...

關於爬蟲裡面的Cookie

把cookie放到headers中直接登入獲取資料 把cookie單獨拿出來利用字串切割轉換成字典然後放到請求的url中進行請求響應獲取引數 cookie dict requests.get url,headers headers headers,cookies cookie dict a b if...

關於Struts裡面的actionForward

1.actionforward的作用 封裝 路徑,通俗點說就是說完成頁面的跳轉和轉向。那它既然是轉向,到底是 還是重定向呢?預設的情況下,actionforward採用的是 的方式進行頁面跳轉的。2.給自己加深下印象,說一下 和重定向的區別。最大的區別就是 的時候,頁面的url位址不變,而重定向的時...