Knowledge Walls
John Peter
Pune, Maharashtra, India
Things to Know [cont'd]
Find String in String manipulation of MS-DOS Commands
3899 Views
How to find string in ms dos command 
This topic is explained about how to find a string in string using ms dos commands. The below syntax to perform find and replace on a string.

Syntax:
%<variable-name>:<find-text>=<replace-text>%

This above statement will return replace string. If a string is replace by empty string then it is not equals to orginal string. This is the way used below to find string in a string.

SET aval=welcome to ms-dos
ECHO %aval:come=%

About aval is variable name. come is search string. empty string is replace string. So output is "wel to ms-dos".
Find string in ms-dos example
@echo off
SET text=Welcome to india

ECHO String is: %text%
ECHO Search string is "come"

IF NOT "%text:come=%"=="%text%" (
    ECHO String is found
) ELSE (
    ECHO String is not found
)

SET /p exit=Bye
Output 
Next Topics
Next lessons of current book.
String manipulation of MS-DOS Commands
String manipulation of MS-DOS Commands
String manipulation of MS-DOS Commands
Previous Topics
Previous lessons of current book.
Commands of MS-DOS Commands
Commands of MS-DOS Commands
Commands of MS-DOS Commands
Commands of MS-DOS Commands
Best Lessons of "MS-DOS Commands"
Top lessons which are viewed more times.
Arithmetic Operators of MS-DOS Commands
Arithmetic Operators of MS-DOS Commands
String manipulation of MS-DOS Commands
String manipulation of MS-DOS Commands
Relational Operators of MS-DOS Commands
Arithmetic Operators of MS-DOS Commands
Logical Operators of MS-DOS Commands
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details