字串處理,找出數字
89aaaa67-09.09900 《變為》89 67 -9.099
#pragma once
#include
#include
#include
#include
#include
using
namespace std;
class
findnum
findnum
(string str)}~
findnum()
void
init
(string &str)
}for
(size_t i =
0; i < len;
)else
if(ch ==
'+')
else i++;}
}bool
isnum
(char c)
void
del0
(string& str)
while
(str[i]
=='0'
) i++
;//此處多餘去尾部的0
int j = str.
size()
-1;if
(haspoint
(str))if
(op!=
'a')
str = op+str.
substr
(i, j - i +1)
;else
str = str.
substr
(i, j - i +1)
;}bool
haspoint
(const string &str)
void
show()
cout << endl;
}private
: vector<
double
> m_strs;};
void
testforston()
- 從例子出發畫歷程圖
- 學會簡單的及時檢驗自己的想法,在main()函式中就具體的例子進行驗證自己預想的結果。
- string c_str
() 將string 轉化為char*-
atof
(str.
c_str()
)-insert
(pos,字串)
-find
(char
)==極大值,表示沒找到
從一字串中找出其無重複最長子串字元及長度
question 給定乙個字串,找出不含有重複字元的最長子串的長度。ex 給定 abcabcbb 沒有重複字元的最長子串是 abc 那麼長度就是3。給定 bbbbb 最長的子串就是 b 長度是1。給定 pwwkew 最長子串是 wke 長度是3。請注意答案必須是乙個子串,pwke 是 子串行 而不是...
C sstream 中處理字串
c 引入ostringstream istringstream stringstream這三個類,要使用他們建立物件就必須包含這個標頭檔案。istringstream的建構函式原形如下 istringstream istringstream string str 它的作用是從string物件str中...
bash中字串處理
得到長度 x abcd 方法一 expr length x 4 方法二 echo 4 方法三 expr x 4 expr 的幫助 string regexp anchored pattern match of regexp in string 查詢子串 expr index x b 2 expr i...