0

こんにちは、テキストボックスで文字列を見つけるのに問題があります。これまでのところ、コンマ文字のみを検出しています。今は午後 23 時、午後 24 時、午前 25 時を入力します。

Dim tdates() As String
Dim numberOfDates, xcount As Integer
tdates = Split(TXTDAYS.Text, ",")
numberOfDates = UBound(tdates)
Dim counter As Integer

' loop through each input
For counter = 0 To numberOfDates
    Dim xdate As String
    xdate = LCase$(tdates(counter))

If Len(xdate) <= 2 Then
  xcount = xcount + 1
  Else
        ' if the original text has am or pm in it, add .5
        If InStr(1, xdate, "am") > 0 Or InStr(1, xdate, "pm") > 0 Then
            xcount = xcount + 0.5 'problem here it doesn't count
        End If
    End If
Next

コンマと am pm 文字列をより適切に検出することにより、これを行うためのより良い方法がある場合。

4

2 に答える 2

0

Splitカンマのテキスト。次に、配列にはすべての単語が含まれます

InStr午前または午後を検索するために使用します。

ReplaceAMとPMに「」を付け、残りのテキストで数値を確認します(検証用)

' split the input on a comma.
dim dates() as String = Split(TXTDAYS.Text, ",")
dim numberOfDates as Integer = UBound(dates)
dim counter as Integer

' loop through each input
For counter = 0 to numberOfDates
    dim dateEntered as String = LCase$(dates(counter))

    ' make sure the text entered is a number (once am and pm are removed)
    dim dateNumber as String =  Replace(Replace(dateEntered, "pm", ""), "am", "")
    if IsNumeric(dateNumber) Then
        COUNT = COUNT + 1

        ' if the original text has am or pm in it, add .5
        if Instr(1, dateEntered , "am") > 0 Or Instr(1, dateEntered , "pm") > 0 Then
            COUNT = COUNT + .5
        end if
    else
        ' do something to indicate invalid input
    end if 
Next
于 2013-03-09T20:01:45.617 に答える
0

instr() を使用して.

s = "admin@foo.com"
d = Mid(s, InStr(1, s, "@") + 1)

変数 d$ は文字列 "foo.com" になります。(@ 記号が存在することを確認することを忘れないでください。そうしないと、ソース文字列全体になってしまいます。)

この投稿から取得..

部分文字列の VB6 インデックス

ありがとう!

@レオ

于 2013-03-09T17:13:27.220 に答える