在第一個字符表達式或備註字段中搜索第二個字符表達式或備註字段,而後用第三個字符表達式或備註字段替換在第一個字符表達式或備註字段中每次出現的第二個字符表達式或備註字段。能夠指定替換開始的位置和替換的次數。sql
- STRTRAN(cSearched, cExpressionSought [, cReplacement] [,nStartOccurrence] [, nNumberOfOccurrences] [, nFlags])
參數ide
cSearched 函數
指定要搜索的字符表達式。
cSearched spa
能夠是備註字段。
cExpressionSoughtip
指定要在 cSearched 中搜索的字符表達式。該搜索區分大小寫。
cExpressionSought 能夠是備註字段。
[, cReplacement] 指定要替換 cSearched 中每次出現的 cSearchFor 的字符表達式。省略 cReplacement 將用空串替換每次出現的 cExpressionSought。
[, nStartOccurrence] 指定第一次要替換的出現的 cExpressionSought。
例如,若是 nStartOccurrence 爲 4,則替換從 cSearched 中第四次出現的 cExpressionSought 開始,先三次出現的 cExpressionSought 保持不變。
省略 nStartOccurrence 默認的替換開始位置爲第一次出現 cExpressionSought。
[, nNumberOfOccurrences] 指定要替換的 cExpressionSought 出現的數量。
省略 nNumberOfOccurrences 將從 nStartOccurrence 指定的出現位置開始,替換全部出現的 cExpressionSought。
[, nFlags] 依照下列值,指定搜索的大小寫敏感性。 ci
注意string
若是隻須要連同必要的參數一塊兒指定 nFlags 設置,請對要忽略的可選參數指定 –1。it
nFlags 值>io
nFlags Value | Description |
0 (default) | Search is case-sensitive, replace is with exact cReplacement text. This is the behavior in the previous version of Visual FoxPro. |
1 | Search is case-insensitive, replace is with exact cReplacement text.table |
2 | Search is case-sensitive, replace is with exact cReplacement text. |
3 | Search is case-insensitive; case of cReplacement is changed to match the case of cExpressionSought, which it replaces. |
也能夠經過將 –1 做爲 nFlags 值傳遞來指定默認行爲。
cReplacement 的大小寫只是在串查找所有爲大寫、小寫或特有的大小寫時才更改。
示例
使用 STORE 命令將串 "abracadabra" 儲存到變量 gcString。STRTRAN( ) 函數用字符 "z" 替換字符 "a",並用 ? 命令顯示 "zbrzczdzbrz" 串。隨後,STRTRAN( ) 從第二次出現開始用字符 "q" 替換三次出現的 "a" 字符,並顯示 "abrqcqdqbra"。
- STORE 'abracadabra' TO gcString
- ? STRTRAN(gcString, 'a', 'z')
- ? STRTRAN(gcString, 'a', 'q', 2, 3)