Changeset 85823 in vbox for trunk/tools/win/vbscript
- Timestamp:
- Aug 18, 2020 3:57:43 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/win/vbscript/helpers.vbs
r85814 r85823 566 566 567 567 568 '' 569 ' Returns the first list of the given string. 570 function StrGetFirstLine(str) 571 dim off 572 off = InStr(1, str, Chr(10)) 573 if off <= 0 then off = InStr(1, str, Chr(13)) 574 if off > 0 then 575 StrGetFirstLine = Mid(str, 1, off) 576 else 577 StrGetFirstLine = str 578 end if 579 end function 580 581 582 '' 583 ' Returns the first word in the given string. 584 ' 585 ' Only recognizes space, tab, newline and carriage return as word separators. 586 ' 587 function StrGetFirstWord(str) 588 dim strSep, offWord, offEnd, offEnd2, strSeparators 589 strSeparators = " " & Chr(9) & Chr(10) & Chr(13) 590 591 ' Skip leading separators. 592 for offWord = 1 to Len(str) 593 if InStr(1, strSeparators, Mid(str, offWord, 1)) < 1 then exit for 594 next 595 596 ' Find the end. 597 offEnd = Len(str) + 1 598 for offSep = 1 to Len(strSeparators) 599 offEnd2 = InStr(offWord, str, Mid(strSeparators, offSep, 1)) 600 if offEnd2 > 0 and offEnd2 < offEnd then offEnd = offEnd2 601 next 602 603 StrGetFirstWord = Mid(str, offWord, offEnd - offWord) 604 end function 605 606 607 '' 608 ' Checks if the string starts with the given prefix (case sensitive). 609 function StrStartsWith(str, strPrefix) 610 if len(str) >= Len(strPrefix) then 611 StrStartsWith = (StrComp(Left(str, Len(strPrefix)), strPrefix, vbBinaryCompare) = 0) 612 else 613 StrStartsWith = false 614 end if 615 end function 616 617 618 '' 619 ' Checks if the string starts with the given prefix, case insenstive edition. 620 function StrStartsWithI(str, strPrefix) 621 if len(str) >= Len(strPrefix) then 622 StrStartsWithI = (StrComp(Left(str, Len(strPrefix)), strPrefix, vbTextCompare) = 0) 623 else 624 StrStartsWithI = false 625 end if 626 end function 627 628 568 629 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 569 630 ' Helpers: Arrays ' … … 1051 1112 if CharIsDigit(Mid(str, i, 1)) <> False then MsgFatal "SelfTest failed: CharIsDigit("&Mid(str, i, 1)&")" 1052 1113 next 1114 1053 1115 if StrVersionCompare("1234", "1234") <> 0 then MsgFatal "SelfTest failed: StrVersionCompare #1" 1054 1116 if StrVersionCompare("1", "1") <> 0 then MsgFatal "SelfTest failed: StrVersionCompare #2" … … 1064 1126 if StrVersionCompare("v1.2.4", "v1.23.4") >= 0 then MsgFatal "SelfTest failed: StrVersionCompare #12" 1065 1127 if StrVersionCompare("v10.0.17163", "v10.00.18363") >= 0 then MsgFatal "SelfTest failed: StrVersionCompare #13" 1066 end sub 1067 1128 if StrVersionCompare("n 2.15.0", "2.12.0") <= 0 then MsgFatal "SelfTest failed: StrVersionCompare #14" 1129 1130 if StrGetFirstWord("1") <> "1" then MsgFatal "SelfTest: StrGetFirstWord #1" 1131 if StrGetFirstWord(" 1 ") <> "1" then MsgFatal "SelfTest: StrGetFirstWord #2" 1132 if StrGetFirstWord(" 1 2 ") <> "1" then MsgFatal "SelfTest: StrGetFirstWord #3" 1133 if StrGetFirstWord("1 2") <> "1" then MsgFatal "SelfTest: StrGetFirstWord #4" 1134 if StrGetFirstWord("1234 5") <> "1234" then MsgFatal "SelfTest: StrGetFirstWord #5" 1135 if StrGetFirstWord(" ") <> "" then MsgFatal "SelfTest: StrGetFirstWord #6" 1136 end sub 1137
Note:
See TracChangeset
for help on using the changeset viewer.