Board logo

标题: [文本处理] 如何判断字符串中是否含有指定字符/内容 [打印本页]

作者: 渣白    时间: 2017-3-31 18:05     标题: 如何判断字符串中是否含有指定字符/内容

本帖最后由 渣白 于 2017-3-31 18:27 编辑

这个句子怎么用批处理代码写出来
密钥TGJ82-KN9YC-FVXR4-CWBQQ-977HC  所有的密钥是这样组成的。25位数  xxxxx-xxxxx-xxxxx-xxxxx-xxxxx

如果 密钥TGJ82-KN9YC-FVXR4-CWBQQ-977HC 找到了A I L O S Z 1 0 BBBBB(多于等于六位) 就显示 密钥包含非法字符



这个是我的写法
if "%Key%|findstr /i "A I L O S Z 1 0 BBBBB" echo 密钥包含非法字符
if "%Key:~5,1%"=="-" (
   if "%Key:~11,1%"=="-" (
   if "%Key:~17,1%"=="-" (
   if "%Key:~23,1%"=="-" (
   if "%Key:~-6,1%"=="-" (
   if "%Key:~29,1%"=="" (
))))))

不能用。。。求个正确的写法//
作者: taofan712    时间: 2017-3-31 19:23

每组五个字符, 每一组之间用-连接
另外是要判断什么,ailosz10 这个是啥意思 ?
作者: ShowCode    时间: 2017-3-31 20:49

  1. @echo off
  2. set "n=0"
  3. set "Key=TGJ82-KN9YC-FVXR4-CWBQQ-977HC"
  4. if "%Key:~5,1%"=="-" (
  5.     if "%Key:~11,1%"=="-" (
  6.         if "%Key:~17,1%"=="-" (
  7.             if "%Key:~23,1%"=="-" (
  8.                 if "%Key:~-6,1%"=="-" (
  9.                     if "%Key:~29,1%"=="" (
  10.                         set n=1
  11.                     )
  12.                 )
  13.             )
  14.         )
  15.     )
  16. )
  17. echo %Key% | findstr /i "A I L O S Z 1 0" > nul && set n=0
  18. if %n% equ 0 (
  19.     echo 密钥包含非法字符
  20. )
  21. pause
复制代码

作者: pcl_test    时间: 2017-3-31 23:11

回复 1# 渣白

%Key:~23,1% equ %Key:~-6,1%
作者: pcl_test    时间: 2017-3-31 23:19

本帖最后由 pcl_test 于 2017-4-25 17:36 编辑

回复 3# ShowCode
不要被楼主的思维带着走……
  1. @echo off&setlocal enabledelayedexpansion
  2. set "Key=TGh82-KN9YC-FVXR4-CWBQQ-977HC"
  3. for /f "tokens=1* delims=-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("#%Key%") do (
  4.     if "%%a%%b" equ "#" (
  5.         if "%Key:~5,1%%Key:~11,1%%Key:~17,1%%Key:~-6,1%%Key:~29%" equ "----" (
  6.             for %%c in (A I L O S Z 1 0 BBBBB) do (
  7.                 if "!Key:%%c=!" neq "!Key!" set f=1
  8.             )
  9.             if not defined f goto end
  10.         )
  11.     )
  12.     set f=1
  13. )
  14. :end
  15. if defined f echo;非法
  16. pause
复制代码

作者: 渣白    时间: 2017-4-1 09:28

回复 5# pcl_test


    谢谢 涨姿势了
作者: 渣白    时间: 2017-4-1 09:30

回复 3# ShowCode


    谢谢,,原来是这样。我一直没写对




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2