Batch string manipulation

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
issenlos
Posts: 1
Joined: 02 Jul 2020 06:34

Batch string manipulation

#1 Post by issenlos » 02 Jul 2020 06:45

Hey my friends,
i'm a newbie to Batch programming (and do not want to spend too much time in it as i dunnot really use it regularly). Maybe soneome of you Pro's can help me out with some quick lines....

I got an url string, of which i iwant to extract a specific string because i want to build a filename of it usinf with ffmpeg. The idea is that my script asks me for an URL and then builds the filename of this string to run ffmpeg

the filenames always look like this:

https://fdsdfasf.stream.fsdafsdafsda.com/live-hls/amlst:evilevi_-sd-ebc76db271adfc05712A=.m3u8

where I always want to extract the sting between the "/amlst:" and the -sd- (whis is always there but positions are not always the same)

Is it possible to find out at which position these two strings are and then extract the string between it? If not with Batch itself - maybe with another tool i can inculde in my batch script?

would be really great if anyone can help me out with this.....
thanks so much in advance!!!

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Batch string manipulation

#2 Post by Aacini » 02 Jul 2020 11:47

Something like this?

Code: Select all

@echo off
setlocal

rem Ask for the URL
rem set /P "url=Enter URL: "
rem Just for testing:
set "url=https://fdsdfasf.stream.fsdafsdafsda.com/live-hls/amlst:evilevi_-sd-ebc76db271adfc05712A=.m3u8"

rem Remove from begining up to "/amlst:" part
set "filename=%url:*/amlst:=%"
rem Remove from "-sd-" part up to string end
set "filename=%filename:-sd-=" & rem "%"

echo "%filename%"
Antonio

Post Reply