ページ 11

数字の抜き出し

Posted: 2007年3月19日(月) 10:46
by Str$(old)
はじめまして。

"234,100円"のなかから 234100 と数字を抜き出したいのですが、
コンマの処理の仕方などわかりません。
どなたか、教えてください

Posted: 2007年3月19日(月) 12:08
by trio
左から一文字ずつ見ていって数字の時だけ文字列を抜き出して繋げれば良いかと

Mid$、For~Next、Len、Ifだけで可能ですのでやって見て下さい

Posted: 2007年3月19日(月) 12:19
by trio
御免なさい
Asc()もいります^^;

Posted: 2007年3月19日(月) 15:46
by Str$(old)
数字であるかの判定はどのようにするのですか?

Posted: 2007年3月19日(月) 17:18
by ゲスト
数字は文字コードが0x30(0)から0x39(9)までなので、それで見分けます。

Posted: 2007年3月19日(月) 18:05
by konisi

コード: 全て選択

Dim buf As String,i As Long,num As Long,sign As Long
buf="234,100円"
If buf[0]=45 then sign=TRUE else sign=FALSE
num=0
For i=0 To Len(buf)-1
    If 48<=buf And buf<=57 then
        num=num*10+buf-48
    End If
Next i
If sign then num=-num
適当に作ったのですが、これではだめでしょうか?

ありがとうございます

Posted: 2007年3月19日(月) 21:34
by Str$(old)
konisiさんのでうまくいきました。ありがとうございます。