+ 1
C# remove all spaces, but not in quotes
I need to a remove spaces from string, but not between quotes. Like if string is: word1 word2 word3 "word4 word5" word6 Output will need to be: word1word2word3"word4 word5"word6 Help me, i know a one way to do it, but its too big way.
3 odpowiedzi
0
Split input with quote obtaining that every even items are the quoted input then split the odds items with space for get the un-quoted items... Example:
Input :
word1 word2 "i am quoted"
Splitting input with quote you would get:
["word1 word2 ", "i am quoted", ""]
Every even items (then at odd index) represent the quoted input then:
quoted= ["i am quoted"]
Instead every odd items (then at even index) represents un-quoted input to split:
unquoted= ["word1 word2"]
that splitted with space
unquoted= ["word1", "word2",""]
Obliviously you can ignore empty strings
0
eh i had a better way, i need easier way
0
What you mean for "better way"? More performant? Less code? What is the real problem?