How to extract a character from a string in a script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

How to extract a character from a string in a script

#1 Post by Velpreso » 11 Feb 2013 11:25

Hi, I would like to draw the first letter of the word TEST (T) but the script written by me is not working. Do you know how to fix it?

Code: Select all

setLocal EnableDelayedExpansion
set str=TEST
set string1=!str:~%1%!
echo %string1%

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Ho to fix this scrypt

#2 Post by Squashman » 11 Feb 2013 12:17

setLocal EnableDelayedExpansion
set str=TEST
set string1=%str:~0,1%
echo %string1%

Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Re: Ho to fix this scrypt

#3 Post by Velpreso » 11 Feb 2013 12:37

Thanks for help but there must be:

Code: Select all

set string1=%str:~3%


your code showing "EST" but thanks for help, now it work as should.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Ho to fix this scrypt

#4 Post by Squashman » 11 Feb 2013 12:38

Velpreso wrote:Thanks for help but there must be:

Code: Select all

set string1=%str:~3%


your code showing "EST" but thanks for help, now it work as should.


Yeah, I just realized that just before you posted. Code is fixed above.

Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Re: Ho to fix this scrypt

#5 Post by Velpreso » 11 Feb 2013 13:25

I have one more question. Do you know of a script that will calculate how many letters in the word is? Or at least if it's possible?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Ho to fix this scrypt

#6 Post by Squashman » 11 Feb 2013 13:43


Post Reply