Excel2000 VBA 文字列操作 /(スラッシュ)で区切られた文字列を分解 [Excel2000 VBA 文字列操作]
Excel2000 VBA 文字列操作 /(スラッシュ)で区切られた文字列を分解
goo天気から取得した最高気温、最低気温の文字列"34 / 28 "を分解する。
Sub 最高最低気温分解()
'goo天気の最低気温、最高気温の文字列を分解する
'
Dim temperature As String
Dim strA, strB As Variant
Dim i, temperatureHL(1) As Integer
'文字設定
temperature = "34 / 28 " '34最高気温 28最低気温
'spaceを削除
temperature = Replace(temperature, " ", "") 'spaceをnullに置換
'区切り文字 / で展開
strA = Split(temperature, "/")
For Each strB In strA
temperatureHL(i) = CInt(strB) 'temperatureHL(0)に34 temperatureHL(1)に28
i = i + 1 'Cint()で文字を数値(integer)に変換
Next
'MsgBoxに表示
MsgBox temperatureHL(0) & vbCrLf + vbCrLf & temperatureHL(1)
End Sub
コメント 0