Hi,
I just want to split a string like:
"1.no data 2.digital input 3.digital output"
into:
1.no data
2.digital input
3.digital output
I spent many hours using the 'for' command trying to do so but failed.
Hope you guys can help me out.
String split question
Moderator: DosItHelp
Re: String split question
How do you identify the end of each part? It can not be a space, because the data have spaces. You may use the point and then rearrange the results a little.
There are several ways to do such a process. I prefer this one:
Output:
A detailed explanation on the method used is given at split string into substrings based on delimiter thread...
EDIT: I like this modification:
Output:
Antonio
There are several ways to do such a process. I prefer this one:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "string=1.no data 2.digital input 3.digital output"
echo %string%
echo/
set "p=%%"
set "i=0" & set "part[!i!]=%string:.=" & call set "part[!i!]=!p!part[!i!]:~0,-2!p!" & set /A "i+=1" & set "part[!i!]=%"
set part[
Code: Select all
1.no data 2.digital input 3.digital output
part[1]=no data
part[2]=digital input
part[3]=digital output
EDIT: I like this modification:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "string=1.no data 2.digital input 3.digital output 6.analog input 9.analog output"
echo %string%
echo/
set "p=%%" & set "part="
set "i=%string:.=" & (if defined part call set "part[!i!]=!p!part:~0,-2!p!" & call set "i=!p!part:~-1!p!") & set "part=%" & set "part[!i!]=!part!"
set part[
Code: Select all
1.no data 2.digital input 3.digital output 6.analog input 9.analog output
part[1]=no data
part[2]=digital input
part[3]=digital output
part[6]=analog input
part[9]=analog output
Re: String split question
It's like magic...
I'll need some time to understand what you did but this works.
Thanks!
I'll need some time to understand what you did but this works.
Thanks!