深入C++ string.find()函數(shù)的用法總結(jié)_Mssql數(shù)據(jù)庫教程
推薦:SQL Server中刪除重復(fù)數(shù)據(jù)的幾個方法數(shù)據(jù)庫的使用過程中由于程序方面的問題有時候會碰到重復(fù)數(shù)據(jù),重復(fù)數(shù)據(jù)導(dǎo)致了數(shù)據(jù)庫部分設(shè)置不能正確設(shè)置
#include <string>#include <iostream>
using namespace std;
void main()
{
復(fù)制代碼 代碼如下:www.hl5o.cn
////find函數(shù)返回類型 size_type
string s("1a2b3c4d5e6f7g8h9i1a2b3c4d5e6f7g8ha9i");
string flag;
string::size_type position;
//find 函數(shù) 返回jk 在s 中的下標(biāo)位置
position = s.find("jk");
if (position != s.npos) //如果沒找到,返回一個特別的標(biāo)志c++中用npos表示,我這里npos取值是4294967295,
{
cout << "position is : " << position << endl;
}
else
{
cout << "Not found the flag" + flag;
}
復(fù)制代碼 代碼如下:www.hl5o.cn
//find 函數(shù) 返回flag 中任意字符 在s 中第一次出現(xiàn)的下標(biāo)位置
flag = "c";
position = s.find_first_of(flag);
cout << "s.find_first_of(flag) is : " << position << endl;
復(fù)制代碼 代碼如下:www.hl5o.cn
//從字符串s 下標(biāo)5開始,查找字符串b ,返回b 在s 中的下標(biāo)
position=s.find("b",5);
cout<<"s.find(b,5) is : "<<position<<endl;
復(fù)制代碼 代碼如下:www.hl5o.cn
//查找s 中flag 出現(xiàn)的所有位置。
flag="a";
position=0;
int i=1;
while((position=s.find_first_of(flag,position))!=string::npos)
{
//position=s.find_first_of(flag,position);
cout<<"position "<<i<<" : "<<position<<endl;
position++;
i++;
}
復(fù)制代碼 代碼如下:www.hl5o.cn
//查找flag 中與s 第一個不匹配的位置
flag="acb12389efgxyz789";
position=flag.find_first_not_of (s);
cout<<"flag.find_first_not_of (s) :"<<position<<endl;
復(fù)制代碼 代碼如下:www.hl5o.cn
//反向查找,flag 在s 中最后出現(xiàn)的位置
flag="3";
position=s.rfind (flag);
cout<<"s.rfind (flag) :"<<position<<endl;
}
說明:
1.如果string sub = ”abc“;
string s = ”cdeabcigld“;
s.find(sub) , s.rfind(sub) 這兩個函數(shù),如果完全匹配,才返回匹配的索引,即:當(dāng)s中含有abc三個連續(xù)的字母時,才返回當(dāng)前索引。
s.find_first_of(sub), s.find_first_not_of(sub), s.find_last_of(sub), s.find_last_not_of(sub) 這四個函數(shù),查找s中含有sub中任意字母的索引。
2.如果沒有查詢到,則返回string::npos,這是一個很大的數(shù),其值不需要知道。
分享:sql刪除重復(fù)數(shù)據(jù)的詳細方法重復(fù)數(shù)據(jù),通常有兩種:一是完全重復(fù)的記錄,也就是所有字段的值都一樣;二是部分字段值重復(fù)的記錄
相關(guān)Mssql數(shù)據(jù)庫教程:
- sql 語句練習(xí)與答案
- SQL Server中刪除重復(fù)數(shù)據(jù)的幾個方法
- sql刪除重復(fù)數(shù)據(jù)的詳細方法
- SQL SERVER 2000安裝教程圖文詳解
- 使用sql server management studio 2008 無法查看數(shù)據(jù)庫,提示 無法為該請求檢索數(shù)據(jù) 錯誤916解決方法
- SQLServer日志清空語句(sql2000,sql2005,sql2008)
- Sql Server 2008完全卸載方法(其他版本類似)
- sql server 2008 不允許保存更改,您所做的更改要求刪除并重新創(chuàng)建以下表
- SQL Server 2008 清空刪除日志文件(瞬間日志變幾M)
- Win7系統(tǒng)安裝MySQL5.5.21圖解教程
- 將DataTable作為存儲過程參數(shù)的用法實例詳解
- 獲取SQL Server表字段的各種屬性實例代碼
Mssql數(shù)據(jù)庫教程Rss訂閱編程教程搜索
Mssql數(shù)據(jù)庫教程推薦
- 詳解SQL Server 2008中的聯(lián)機事務(wù)處理
- 使用Sqlserver事務(wù)發(fā)布實現(xiàn)數(shù)據(jù)同步(sql2008)
- SQL Server 中易混淆的數(shù)據(jù)類型
- 如何將SQL 2000日志遷移到SQL Server 2008
- 關(guān)于避免在 PL/SQL 中使用嵌套游標(biāo)查詢
- 微軟數(shù)據(jù)平臺開發(fā)與SQL Server 2008
- SQL Server 2008 R2英文版安裝圖文教程
- 解讀SQL Server與Oracle數(shù)據(jù)庫在安全性上的異同
- 用sp_lock診斷SQL Sever的性能問題
- 如何讓新手防范SQL注入攻擊
- 相關(guān)鏈接:
- 教程說明:
Mssql數(shù)據(jù)庫教程-深入C++ string.find()函數(shù)的用法總結(jié)
。