문제

배치를위한 카드 게임을 개발하고 있습니다. [완료되면 링크를 줄 것입니다

기본적으로 내가하고 싶은 것은 'set' '%random%'에서 '%numbs%'입니다.

set %numbs%=%random%

그런 다음 사용자가 표시된 % 임의 % 숫자에서 하나의 값을 입력하기를 원합니다.

echo %numbs%
Set nuchoo=
set /p nuchoo=Number: 

내 질문은 이제 사용자가 입력 한 값이 % numbs % 값인지 확인하는 방법에 관한 것입니다. 그렇다면

GOTO :validnucho

그렇지 않다면

GOTO :unvalidnucho

다음과 같은 경우 : ValidNucho, 해당 숫자를 % numbs % var에서 삭제해야합니다. 비 내가 아는 나머지.

도움이 되었습니까?

해결책

이것은 당신을 시작해야합니다

다음을 instr.cmd로 저장하십시오

@echo off 

rem These two lines allow tracing to be turned on by entering 
rem set TRACE=ECHO on the cmd line
  if not defined TRACE set TRACE=rem
  %TRACE% on 

rem Allow use of delayed variable expansion using !  
  setlocal ENABLEDELAYEDEXPANSION 

  if  /I [%1]==[Test] ( 
    call :Test
    goto :eof
    )

:Instr 
  set mTestStr=%1

rem  set /a does arithmatic
  set /a TestIdx=0
  set Found=N
  set CopiedStr=

  :startLoop

rem extract character at index TestIndx to test   
    set TestedChar=!mTestStr:~%TestIdx%,1!
rem echo TestedChar if trace is on 
    %TRACE% %TestedChar%

    If [!TestedChar!]==[] (
      goto :exitInstr
    )

    If [%TestedChar%]==[%2] (
rem   Testedchar matchs search character, 
rem   so we have found the char we were looking for    
      if %Found%==Y (
        set CopiedStr=%CopiedStr%%TestedChar%
      ) 
      set Found=Y
    ) else (
      set CopiedStr=%CopiedStr%%TestedChar%
    ) 



rem Increment Index       
    SET /a TestIdx=TestIdx+1

  goto :startLoop

:exitInstr

rem endlocal but keep CopiedStr and Found
  endlocal & set CopiedStr=%CopiedStr% & set Found=%Found%

goto :eof

:Test    


  call :Instr abcde c
  call :Verify Y %Found% "call :Instr abcde c - Found"
  call :Verify abde, %CopiedStr% "call :Instr abcde c - CopiedStr"

  call :Instr abcde x
  call :Verify N %Found% "call :Instr abcde x - Found"
  call :Verify abcde, %CopiedStr% "call :Instr abcde x - CopiedStr"

  call :Instr abcdec c
  call :Verify Y %Found% "call :Instr abcdec c - Found"
  call :Verify abdec, %CopiedStr% "call :Instr abcdec c - CopiedStr"


    echo Tests Done

goto :eof   

:Verify
  set Expected=%1
  set Expected=%Expected:"=%

  set Actual=%2
  set Actual=%Actual:"=%

  set Msg=%3
  set Msg=%msg:"=%

  If not "%Expected%"=="%Actual%"   (
    echo Failed: Expected "%Expected%" but was "%Actual%"  - %Msg%
  ) else ( 
    echo OK Expected "%Expected%" - %Msg%
  )

goto :eof   
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top