我正在为“TechnoExpo”开展一个学校项目。我需要知道如何在两个“()”之间拉出字符串,我需要知道如何计算四个变量。
Input One Example: 6(3)
Input Two Example: 2(7)
我需要将名为“X1”的变量设置为“6”,将名为“Y1”的变量设置为“3”,将“2”设置为名为“X2”的变量,将“7”设置为名为“变量”的变量“7” Y2" 。接下来我需要计算(“Y2” - “Y1”)除以(“X2” - “X2”)。从这里我可以自己显示信息。这是一个beta批处理文件版本。
@Echo Off
:StartUpConfiguration
Cls
Mode Con Cols=50 Lines=25
Color 0F
:Start
Set /P CordinateOne=[One]
Set /P CordinateTwo=[Two]
For /F "Tokens=1,2 delims=()" %%A In ("%CordinateOne%") Do Set "X1=%%A" & set "Y1=%%B"
For /F "Tokens=1,2 delims=()" %%A In ("%CordinateTwo%") Do Set "X2=%%A" & set "Y2=%%B"
Echo Slope:
Set /A Y=%Y2%-%Y1%
Set /A X=%X2%-%X1%
Set /A M=%Y%/%X%
Echo [%M%]
Echo.
Echo %Y2% - %Y1% [%Y%]
Echo %X2% - %X1% [%X%]
Pause
答案 0 :(得分:2)
strInput1 = UserInput( "CordinateOne=:" )
strInput2 = UserInput( "CordinateTwo=:" )
substr1=Split(strInput1,"(")
substr2=Split(strInput2,"(")
X1=CInt(substr1(0))
Y1=CInt(Split(substr1(1),")")(0))
X2=CInt(substr2(0))
Y2=CInt(Split(substr2(1),")")(0))
X=X2-X1
Y=Y2-Y1
M=Y/X
MI=Y Mod X
Wscript.Echo "[" & M & "]" & "or [" & M & "." & MI & "]"
Wscript.Echo ""
Wscript.Echo Y2 & "-" & Y1 & " [" & Y & "]"
Wscript.Echo X2 & "-" & X1 & " [" & X & "]"
Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Check if the script runs in CSCRIPT.EXE
If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
' If so, use StdIn and StdOut
WScript.StdOut.Write myPrompt & " "
UserInput = WScript.StdIn.ReadLine
Else
' If not, use InputBox( )
UserInput = InputBox( myPrompt )
End If
End Function
您可以使用cscript.exe
和wscript.exe
来执行此操作。不对输入进行验证。
答案 1 :(得分:1)
回答你的头衔How to extract part of string in Visual Basic Scripting (VBS)?
:
以下是您需要的所有信息:
示例:
txt="This is a beautiful day!"
wscript.Echo(Mid(txt,1,1))