Welcome, guest | Sign In | My Account | Store | Cart

As you know there are no escape characters such as "\t" in the windows command language but it does not mean that we can not format text. Command prompt has its own tricks. At firstly, you need declare enabledelayedexpansion after setlocal command in your batch file to get access for some interesting things; secondly, use <code><nul set /p "str=[string]"</code> construction which is equal print function in C language. OK, next batch file print multiplication table.

Batch, 14 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@echo off
 setlocal enabledelayedexpansion
  for /l %%i in (1, 1, 9) do (
    for /l %%j in (1, 1, 9) do (
      set /a "res=%%i * %%j"
      rem This condition imitate "\t" character
      if "!res:~1,2!" equ "" (set "res= !res!,") else set "res=!res!,"
      rem Imitation of C's print function
      <nul set /p "res=   !res:,= !"
    )
    echo.
  )
 endlocal
exit /b
Created by greg zakharov on Tue, 18 Jun 2013 (MIT)
Batch recipes (42)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks