Introduction: Editing Variables

         Hello to all. (This is my first instructable so be nice.) In most informational web sites (ex, Webipidea) you can search for certain topics and facts. In this Instructable, I will show you how to edit out parts of user input and use them as search keywords.

Step 1: How to Do It

Here's how to do it:
First, set a variable (I used %a% for this example, but you can use any thing.)

Shows all but the first 2 letters                              %a:~2%
Shows all but the last two letters                          %a:~0,-2%
Shows all but the first 2 and Last 2 letters         %a:~2,-2%
Only shows the first 2 letters                                 %a:~0,2%
Only shows the last 2 letters                                 %a:~-2%
Only shows the first 2 letters and last 2 letters  %a:~0,2%%a:~-2%

I used 2 for every example, be you can use any number you want.
I've included a program that asks for a word, then cut it up into bits using only the methods used above. You can download it from the bottom or copy and paste it into Notepad if you don't trust me.  ;(

@echo off
title time editer
cls
color 70
echo Write a word 6 letters or more long.
set /p a=
cls
echo Full word: %a%
echo.
echo First 2 letters gone:
echo %a:~2%
echo.
echo Last two letters gone:
echo %a:~0,-2%
echo.
echo First 2 letters:
echo %a:~0,2%
echo.
echo Last 2 letters:
echo %a:~-2%
echo.
echo First 2 and Last 2 letters
echo gone:
echo %a:~2,-2%
echo.
echo First 2 letters and last 2
echo letters: %a:~0,2%%a:~-2%
pause >nul


This won't edit the variable's value, it's just some of the variables value from being seen or used. If you wanted to see if someone typed in something starting with your name, you would write:

set /p imput=
if %imput:~0,4%==NAME echo Quit talking about me.

The value itself would noth change, only what's seen or used.

set a=NATHAN
echo %a:~0,2%
echo %a%
pause

The screen woud show:

NA
NATHAN
Press any key to continue . . .

That would show the first 2 letters of the value of the variable "a," but the value itself doesn't change. If you wanted to change the value of a variable with this method, you would do this:

set a=NATHAN
set b=%a:~0,2%
set a=%b%
echo a
pause

The screen would show:

NA

Have fun!

Step 2: Another Example

Another thing people sometimes don't know is that their are certain things that you can add to your commands to adjust how they appear on the screen. Here's an example.

@echo off
cls
(commands)
pause
(commands)
exit

-would turn echo off, clear the screen, execute some commands, pause showing "Press any key to continue . . .", execute some commands, then exit.
 Adding ">nul" at the end of any of the commands would stops the command from showing it's results.

@echo off
cls
Hi Sean
pause >nul
cls
Long time - no see.
pause >nul
exit

It works be saving the results as nul. (I'm not quit sure what nul is. If any one knows, Please tell me!) This is useful if you hid a copy command in a friends guessing game.