質問するログイン新規登録

回答編集履歴

2

少し訂正

2020/09/18 05:14

投稿

ttyp03
ttyp03

スコア17002

answer CHANGED
@@ -22,7 +22,8 @@
22
22
  Set re = New RegExp
23
23
  re.Pattern = "^0*"
24
24
  Set mc = re.Execute(Target)
25
- MyStr = re.Replace(Target, String(Len(mc.Item(0)), " "))
25
+ 'MyStr = re.Replace(Target, String(Len(mc.Item(0)), " "))
26
+ MyStr = re.Replace(Target, String(mc.Item(0).Length, " "))
26
27
 
27
28
  Debug.Print MyStr
28
29
  ```

1

正規表現版追加

2020/09/18 05:14

投稿

ttyp03
ttyp03

スコア17002

answer CHANGED
@@ -8,4 +8,21 @@
8
8
 
9
9
  ' Targetの文字数で処理する場合
10
10
  MyStr = Right(String(Len(Target), " ") & Val(Target), Len(Target))
11
+ ```
12
+
13
+ ---
14
+ 正規表現を使った場合も書いておきます。
15
+ あまり詳しくはないので2段階になってしまいましたが、たぶんこんな感じじゃないかと思います。
16
+
17
+ ```VBA
18
+ Dim re As RegExp
19
+ Dim mc As MatchCollection
20
+
21
+ Target = "0001203"
22
+ Set re = New RegExp
23
+ re.Pattern = "^0*"
24
+ Set mc = re.Execute(Target)
25
+ MyStr = re.Replace(Target, String(Len(mc.Item(0)), " "))
26
+
27
+ Debug.Print MyStr
11
28
  ```