投稿日 | : 2007/03/29(Thu) 12:33 |
投稿者 | : nobu |
Eメール | : |
URL | : |
タイトル | : Re^4: 文字列の前後からスペース削除 |
> Replace関数ですと、文字列中のスペースまで置換してしまいます。
こうならない様にする為には下記の様に3ケに分割してから処理すれば?
左側の空白部分 + 前後に空白が無い部分 + 右側の空白部分
下記では文字列の前後に空白がある事を分かるように * と @ を追加してある。
Dim tmp As String
Dim tmp1 As String
Dim tmp_L As String
Dim tmp_R As String
Dim space_L As String
Dim space_R As String
tmp = " abc de fg "
tmp1 = Trim$(tmp) '前後の空白を全て削除
tmp_L = RTrim$(tmp) '右側の空白を削除
tmp_R = LTrim$(tmp) '左側の空白を削除
Label1.Caption = "*" & tmp & "@"
Label2.Caption = "*" & tmp1 & "@"
Label3.Caption = "*" & tmp_L & "@"
Label4.Caption = "*" & tmp_R & "@"
space_L = Replace(tmp_L, tmp1, "") '左側の空白部分のみ
space_R = Replace(tmp_R, tmp1, "") '右側の空白部分のみ
Label5.Caption = "*" & space_L & "@"
Label6.Caption = "*" & space_R & "@"
space_L space_R をそれぞれ半角の空白、全角の空白削除で処理をしてから
適宜文字列結合すると言うのは.....?