• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Welcome to ErranLi's Blog!

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              106 Posts :: 1 Stories :: 97 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(12)

            搜索

            •  

            積分與排名

            • 積分 - 174947
            • 排名 - 151

            最新評論

            閱讀排行榜

            (引用)


            {------------------------------------------------------------------------------}
            { procedure ReadStrValues                                                      }
            {                                                                              }
            { 功能說明: 根據指定的分隔符將一個字符串分解為若干個子串                       }
            {           如果傳遞的子串數量超過源串可以解析的字串數, 則多傳的子串將置為空串 }
            { 參    數:                                                                    }
            {   Str   : 待分解的字符串                                                     }
            {   StrArr: 存放分解后的子串的數組, 以字符串指針數組傳遞                       }
            {   Ch    : 分隔符定義, 缺省為 ";"                                             }
            {------------------------------------------------------------------------------}
            procedure ReadStrValues(Str: string; StrArr: array of PString; Ch: Char = ';');
            var
              I, StrLen, StrPos, ArrLen, ArrIndex: Integer;
            begin
              StrLen := Length(Str);      // 字符串長
              ArrLen := Length(StrArr);   // 待取出的字符串個數
              if ArrLen = 0 then Exit;    // 如果字符串指針數組中無元素,則直接退出

              StrPos := 1;                // 當前讀到的字符串位置
              ArrIndex := 0;              // 當前字符串指針數組位置

              // 此處將 Str 長度加1,用于后面判斷是否已讀完整個字串
              for I := 1 to StrLen + 1 do
              begin
                // 注意此處條件位置不可倒置(驟死式判斷)
                if (I = StrLen + 1) or (Str[I] = Ch) then
                begin
                  // 拷貝讀到的字符串
                  StrArr[ArrIndex]^ := Copy(Str, StrPos, I - StrPos);
                  StrPos := I + 1;
                  // 如果需要讀的字符串指針數組已完成,則退出
                  Inc(ArrIndex);
                  if ArrIndex >= ArrLen then Exit;
                end;
              end;

              // 檢查是否所有的字符串指針都讀到了,如果沒有讀到,將被設置為空串
              for I := ArrIndex to ArrLen - 1 do
                StrArr[I]^ := '';
            end;


            {------------------------------------------------------------------------------}
            { 測試該函數                                                                   }
            {------------------------------------------------------------------------------}

            procedure TForm1.FormCreate(Sender: TObject);
            const
              SampleStr = '張三;男;41';
            var
              S1, S2, S3, S4: string;
            begin
              // 正常字串解析
              S1 := 'S1';  S2 := 'S2';  S3 := 'S3';  S4 := 'S4';
              ReadStrValues(SampleStr, [@S1, @S2, @S3]);
              ShowMessage(Format('"%s", "%s", "%s", "%s"', [S1, S2, S3, S4]));

              // 待讀字串少于源串內容測試
              S1 := 'S1';  S2 := 'S2';  S3 := 'S3';  S4 := 'S4';
              ReadStrValues(SampleStr, [@S1, @S2]);
              ShowMessage(Format('"%s", "%s", "%s", "%s"', [S1, S2, S3, S4]));

              // 待讀字串多于源串內容測試
              S1 := 'S1';  S2 := 'S2';  S3 := 'S3';  S4 := 'S4';
              ReadStrValues(SampleStr, [@S1, @S2, @S3, @S4]);
              ShowMessage(Format('"%s", "%s", "%s", "%s"', [S1, S2, S3, S4]));

              // 待讀字串為空測試
              S1 := 'S1';  S2 := 'S2';  S3 := 'S3';  S4 := 'S4';
              ReadStrValues(SampleStr, []);
              ShowMessage(Format('"%s", "%s", "%s", "%s"', [S1, S2, S3, S4]));

              // 源串為空測試
              S1 := 'S1';  S2 := 'S2';  S3 := 'S3';  S4 := 'S4';
              ReadStrValues('', [@S1, @S2, @S3]);
              ShowMessage(Format('"%s", "%s", "%s", "%s"', [S1, S2, S3, S4]));
            end;

            posted on 2006-12-07 20:17 erran 閱讀(1259) 評論(0)  編輯 收藏 引用 所屬分類: Delphi
            久久综合88熟人妻| 久久精品国产99久久香蕉| 亚洲中文字幕久久精品无码APP| 久久久久女教师免费一区| 99久久中文字幕| 久久久久婷婷| 99久久综合狠狠综合久久止| 久久综合五月丁香久久激情| 久久久久久九九99精品| 久久久久国产日韩精品网站| 性色欲网站人妻丰满中文久久不卡| 久久超碰97人人做人人爱| 国产精品久久久久一区二区三区| 久久99精品九九九久久婷婷| 亚洲AV无码一区东京热久久| 精品综合久久久久久97超人| 国产精品久久久久蜜芽| 国产精品综合久久第一页| 久久精品中文字幕无码绿巨人| 无码人妻少妇久久中文字幕 | 香蕉久久一区二区不卡无毒影院| segui久久国产精品| 欧美久久久久久精选9999| 69国产成人综合久久精品| 亚洲va中文字幕无码久久| 狠狠综合久久AV一区二区三区| 久久91这里精品国产2020| 久久亚洲AV成人无码电影| 亚洲欧美久久久久9999| 99久久无码一区人妻a黑| 免费精品久久天干天干| 日韩久久久久中文字幕人妻| 国产精品内射久久久久欢欢| 久久r热这里有精品视频| 久久91精品久久91综合| 久久精品国产91久久综合麻豆自制 | 欧洲精品久久久av无码电影 | 久久99国产亚洲高清观看首页 | 国产激情久久久久影院小草| 国产偷久久久精品专区| 色综合久久无码中文字幕|