全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:946
推到 Plurk!
推到 Facebook!

請問 字串的處理,有點像資料結構處理的觀念

尚未結案
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-07 17:04:41 IP:210.192.xxx.xxx 未訂閱
請問站上大大,小弟有一排字串如下: my name is %{henry} , my address is %{henryaddr} 小弟想做一個判斷,讓它遇到 %{henry} 就可以知道去索引到 Henry 的名字進去,遇到 %{henryaddr} 時就代索引到「henry 他的住址進入」,也就是小弟想讓它判斷後的字串變成如下: my name is Henry , my address is in Taiwan 以提高擴充性,請問有前輩有比較好的方法嗎?? 因為 %{henry} 這些字串是由其它程式輸入,而由小弟的程式做判斷,所以小弟並不能用 printf 的 my name is %s , my address is %s ,這種方式,請問有前輩能幫小弟解答一下嗎??
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-07 18:28:23 IP:61.66.xxx.xxx 未訂閱
【BCB】【問題】求教如何抓取Memo中某個字串. http://delphi.ktop.com.tw/topic.php?topic_id=62332 裡面有教字串取代的方法 反正遇到特定的字串你就取代為你想要的字串
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-07 20:09:48 IP:210.192.xxx.xxx 未訂閱
引言: 【BCB】【問題】求教如何抓取Memo中某個字串. http://delphi.ktop.com.tw/topic.php?topic_id=62332 裡面有教字串取代的方法 反正遇到特定的字串你就取代為你想要的字串
blk5743 兄:謝謝您的指點,這樣小弟董了,只是小弟想再了解一下,如果不用 StringReplace 這個func 而用一班 C 在用的func 是否也有取代這樣功能的呢?因為小弟有可能在 linux 上面也會用到這種應用。謝謝。
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-08 23:34:35 IP:61.31.xxx.xxx 未訂閱
StringReplace應該是BCB特有的吧 一般的C不知道有沒有類似的(我不在辦公室沒辦法查書)    這是我在BCB 6 Help 查Replace得到的,可以參考一下    
 
Example    //
// replace.cpp
//
 #include 
 #include 
 #include 
 #include 
 #include 
 using namespace std;
 template
 struct all_true : public unary_function
 {
   bool operator()(const Arg&){ return 1; }
 };
 int main()
 {
   //Initialize a vector with an array of integers
   int arr[10] = {1,2,3,4,5,6,7,8,9,10};
   vector v(arr, arr 10);
   //Print out original vector
   cout << "The original list: " << endl << "     ";       copy(v.begin(),v.end(),ostream_iterator
       (cout," "));
   cout << endl << endl;
   //Replace the number 7 with 11
   replace(v.begin(), v.end(), 7, 11);       // Print out vector with 7 replaced, 
   // s.b. 1 2 3 4 5 6 11 8 9 10
   cout << "List after replace " << endl << "     ";
   copy(v.begin(),v.end(),ostream_iterator(cout," "));
   cout << endl << endl;
   //Replace 1 2 3 with 13 13 13
   replace_if(v.begin(), v.begin() 3, all_true(), 13);       // Print out the remaining vector, 
   // s.b. 13 13 13 4 5 6 11 8 9 10
   cout << "List after replace_if " << endl << "     ";
   copy(v.begin(),v.end(),
        ostream_iterator(cout," "));
   cout << endl << endl;
   return 0;
 }    Program Output    The original list:
     1 2 3 4 5 6 7 8 9 10    List after replace
     1 2 3 4 5 6 11 8 9 10    List after replace_if
     13 13 13 4 5 6 11 8 9 10    Warnings    If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you need to write:    vector >    instead of:    vector    If your compiler does not support namespaces, then you do not need the using declaration for std.    See Also    replace_if, replace_copy, replace_copy_if
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-01-09 20:55:15 IP:210.192.xxx.xxx 未訂閱
引言: StringReplace應該是BCB特有的吧 一般的C不知道有沒有類似的(我不在辦公室沒辦法查書) 這是我在BCB 6 Help 查Replace得到的,可以參考一下
blk5743 兄謝謝您,我想那個StringReplace 是bcb 自己的,只是我到搜尋網站上搜在linux 上有否有關於 Replace 的func 似乎好像沒有耶,不知 blk5743 兄您週一時能否幫小弟查看書上是否有,而小弟上班時也到linux 查看有沒有這個相關的func 可以使用,不好意思托了兩天才給分,因為沒上線不好意思。
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-01-10 09:35:48 IP:61.66.xxx.xxx 未訂閱
標準函式有一個replace要引入 你用Compile的Help應該會查到用法(我的書有八種格式,有點多,沒辦法Keyin)
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-01-10 11:12:55 IP:211.76.xxx.xxx 未訂閱
引言: 標準函式有一個replace要引入 你用Compile的Help應該會查到用法(我的書有八種格式,有點多,沒辦法Keyin)
blk5743 兄,謝謝您,我在linux 上的 裡並找不到,有關於replace的函式,可能是linux 和 windows 有差異吧,謝謝您 blk5743 兄,我再找找看,不好意思一直打擾您。
系統時間:2024-06-19 0:38:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!