2

テストに必要な Microsoft QBasic で時間 (月/日/年) を解析する方法。

s = 'PT1H28M26S'

私は取得したい:

num_mins = 88
4

2 に答える 2

1

このような時刻文字列は、以下のコードで解析できますが、本当の問題は
、2015 年になっても QBasic を使用しているのは誰だ!?

CLS
s$ = "PT1H28M26S"

' find the key characters in string
posP = INSTR(s$, "PT")
posH = INSTR(s$, "H")
posM = INSTR(s$, "M")
posS = INSTR(s$, "S")

' if one of values is zero, multiplying all will be zero
IF ((posP * posH * posM * posS) = 0) THEN
  ' one or more key characters are missing
  nummins = -1
  numsecs = -1
ELSE
  ' get values as string
  sHour$ = MID$(s$, posP + 2, (posH - posP - 2))
  sMin$ = MID$(s$, posH + 1, (posM - posH - 1))
  sSec$ = MID$(s$, posM + 1, (posS - posM - 1))

  ' string to integer, so we can calculate
  iHour = VAL(sHour$)
  iMin = VAL(sMin$)
  iSec = VAL(sSec$)

  ' calculate totals
  nummins = (iHour * 60) + iMin
  numsecs = (iHour * 60 * 60) + (iMin * 60) + iSec
END IF

' display results
PRINT "Number of minutes: "; nummins
PRINT "Number of seconds: "; numsecs
PRINT "QBasic in 2015! w00t?!"
于 2015-04-17T09:46:30.597 に答える