Score:0

Batch - Extract string before the specified character

cz flag

How to get the string before the character hyphen? The following code gets the string after the hyphen. How can I reverse this?

set string=1.0.10-SNAPSHOT

echo %string:*-=%

SNAPSHOT

But I want the 1.0.10 instead of SNAPSHOT of if the string is RELEASE

MohammadReza moeini avatar
us flag
You want extract 1.0.10?
John Doe avatar
cz flag
yes that's right
Score:0
us flag

for extract string before hyphen (special charcter) you need used for

@echo off
set string=1.0.10-SNAPSHOT
echo %string%
for /f "tokens=1 delims=-" %%a in ("%string%") do (
  echo %%a
  )
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.