Articles

Solved How to split at a character in a string

February 19, 2013 at 15:37:07
Specs: Windows 7

Hello,
I have the string "Name: Nick" and I need to split at the ": " so I have two separate strings, "Name" and "Nick". I know how to get "Name" but I still can't find "Nick". Thanks in advacne,
Nick

See More: How to split at a character in a string

Report •


✔ Best Answer
February 20, 2013 at 19:57:15

@echo off & setlocal
set string=name: beelzebub
for /f "tokens=1,2 delims=:" %%a in ("%string%") do set tag=%%a&set value=%%b
echo tag: %tag%
echo value: %value%


#1
February 19, 2013 at 16:11:11

What programming language are you using here?

Jonas "Jackal" Lear
http://www.sbccrew.com
Serving the South Bay Since 1999


Report •

#2
February 20, 2013 at 05:57:10

Batch, I tagged that but I guess tags aren't quite prominent enough :/

Report •

#3
February 20, 2013 at 06:54:19

The example you gave breaks at a space, so if your file looks like this:

name nick
color green

:: ===== script starts here ===============
::
:: breaker.bat 2013-02-20 21:50:36.89
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=1-2 delims= " %%a in (myfile) do (
echo.%%a
echo.%%b
)
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
February 20, 2013 at 19:57:15
✔ Best Answer

@echo off & setlocal
set string=name: beelzebub
for /f "tokens=1,2 delims=:" %%a in ("%string%") do set tag=%%a&set value=%%b
echo tag: %tag%
echo value: %value%

Report •


Ask Question