how will we can split a string ex: str='samuelsamuel123'
the question is, I want unique laters from this str and and each later is how many times printed
ans: unique: samuel123
s 2 times
a 2 times
.
.
.
like this
how will we can split a string ex: str='samuelsamuel123'
Moderator: DosItHelp
Re: how will we can split a string ex: str='samuelsamuel123'
Depending on the characters you want to use you could do something like that:
penpen
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
for /f "delims==" %%a in ('set "character["') do set "%%a="
set "str=samuelsamuel123"
for /f %%a in ('cmd /d /u /c"echo(%str%" ^| find /v ""') do @set /a "character[%%a]+=1"
set "character["
goto :eof
penpen
Re: how will we can split a string ex: str='samuelsamuel123'
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "str=samuelsamuel123"
set "unique="
for /F "delims=" %%a in ('cmd /U /C set /P "=%str%" ^<nul ^| find /V ""') do (
if not defined letter[%%~a] set "unique=!unique!%%a"
set /A "letter[%%~a]+=1"
)
echo Unique: %unique%
set letter[
Output:
Code: Select all
Unique: samuel123
letter[1]=1
letter[2]=1
letter[3]=1
letter[a]=2
letter[e]=2
letter[l]=2
letter[m]=2
letter[s]=2
letter[u]=2
Antonio