abap查詢字串中最後一次出現的字元 正則匹配

2021-10-10 11:45:45 字數 1161 閱讀 1169

如何查詢字串中某字元最後一次出現的位置呢,可使用find語句,abap中可使用正規表示式regex的語句就只有find以及replace語句了。

以下**塊表示了如何操作:

data: text type char100,

moff type i,

mlen type i,

mcnt type i.

text = '123a45a678'.

write: / '轉換前:',text.

find all occurrences of 'a'

in text

match offset moff "最後一次出現位置

match length mlen "匹配字元長度

match count mcnt. " 計數匹配次數

write: / '出現位置和長度:',moff,mlen.

"可進一步做替換處理

replace 'a' in

section offset moff length mlen of

text with 'b'.

write: / '轉換後:',text.

下面是複雜的正規表示式匹配例子:

data text type string.

data result_tab type match_result_tab with header line.

text = 'shalalala!'.

"匹配la,並且la之後必須是! (?:...)表示非捕獲組(分組,但不捕獲);()表示捕獲組(分組)

找字串中最後乙個只出現一次的字元

找字串中最後乙個只出現一次的字元 題目描述 給定乙個只包含小寫字母的字串,請你找到最後乙個僅出現一次的字元。輸入格式 乙個字串,長度小於 100000。輸出格式 輸出最後乙個僅出現一次的字元,若沒有則輸出 no。輸入樣例 abcabd 輸出樣例 d這道題難瓜剛開始還不會做,結果我的好朋友提醒我就會了...

bat批處理查詢字元在字串中最後出現的位置

echo off setlocal enabledelayedexpansion 查詢字元在字串中最後出現的位置 set strchrr str str1 this is a test string set strchrr str ch1 t 注意,這裡是區分大小寫的!set strchrr str...

查詢字串中最長的連續數字子串

include using namespace std int max num str char pstr,char output char p first pstr char p last pstr int num 0 while p first 0 if p first 0 p last p f...