- Oct
- 364
- 17
How can I accurately count commas in a string, preferably with @count?
Basically, I have some strings that should not contain commas but sometimes do. I can convert any commas to spaces with @replace and then replace any double spaces with a single space.
But, if there are no commas, I want to leave the string alone -- even if it has double spaces.
I have tried a number of variations of @count but none of them work, e.g:
Set x=abc, 123, def
Basically, I have some strings that should not contain commas but sometimes do. I can convert any commas to spaces with @replace and then replace any double spaces with a single space.
But, if there are no commas, I want to leave the string alone -- even if it has double spaces.
I have tried a number of variations of @count but none of them work, e.g:
Set x=abc, 123, def
- echo %@count[,, %x]
- echo %@count[^,, %x]
- echo %@count[",", %x]
- echo %@count[`,`, %x]
- echo %@count[',', %x]
- echo %@count[%@char[44], %x]