cowbearcar 發表於 17-5-31 10:52

簡單文字取代 Function STRTRAN

// StrTran("BCDBCDFEDFED", "D", "Z") => Replace all "D" with "Z" in String!
// Return "BCZBCZFEZFEZ"
// = REPLACE in Excel
Input: BaseStr(StringSimple), TakeStr(StringSimple), ReplStr(StringSimple);
variable: BaseLen(0), InLen(0);
variable: ResultStr(""), LeaveStr("");

BaseLen = StrLen(BaseStr);
InLen = InStr(BaseStr, TakeStr);

If InLen = 0 Then
    ResultStr = BaseStr   // not found
Else begin
    ResultStr = LeftStr(BaseStr, InLen - 1) + ReplStr;
    LeaveStr = MidStr(BaseStr, InLen + StrLen(TakeStr), StrLen(BaseStr)-StrLen(TakeStr));
   
    While InStr(LeaveStr, TakeStr) > 0 begin
      InLen = InStr(LeaveStr, TakeStr);
      ResultStr = ResultStr + LeftStr(LeaveStr, InLen - 1) + ReplStr;
      LeaveStr = MidStr(LeaveStr, InLen + StrLen(TakeStr), StrLen(LeaveStr)-StrLen(TakeStr));
    End;
   
    ResultStr = ResultStr + LeaveStr;
End;

StrTran = ResultStr;


這樣,若你想匯出 USD/JPY 或其他 Symbol 中間有/去檔案時
毋須個別處理 / 的位置在那裏!

簡單一句就可以解決了。

print("D:\" + strtran(symbol, "/", ""), "Date"..... );
頁: [1]
查看完整版本: 簡單文字取代 Function STRTRAN