1
string mystr = clause.Replace("\"", "");

whereArray = mystr.TrimEnd(']').TrimStart('[').Split(',');

so in whereArray i get this

"DigitalMedia","=","Snapchat","AND","Impressions","IN","14,15,24"

so Basically i want like this

whereArray[0] = "DigitalMedia"

whereArray [1] = "="

whereArray [2] = "Snapchat"

whereArray [3] = "AND"

whereArray [4] = "Impressions"

whereArray [5] = "IN"

whereArray [6] = "14,15,24"

and trying this

whereArray = mystr.TrimEnd(']').TrimStart('[').Split(',');

this is what i get

Ashish Shukla
  • 129
  • 1
  • 10
  • Could you post what the string `myStr`looks before Splitting? – SteveZ Jan 23 '20 at 07:57
  • ["OrphanCampaignName","=","Snapchat","AND","Impressions","IN","14,15,24"] this is the string myStr , i dont want to split again 14,15,24 as it is whole term which i will save and give to db as query in future – Ashish Shukla Jan 23 '20 at 08:17
  • 5
    It looks like you're receiving a JSON array of strings. Why are you trying to manipulate it using raw string functions when you could just use a JSON library? – Damien_The_Unbeliever Jan 23 '20 at 08:28
  • ["OrphanCampaignName","=","Snapchat"] this is one condition for now i have max 5 conditions but when i pick this value "Snapchat " it exactly comes in my registered array index but when ["Impressions","IN","14,15,24"] have this it breaks it differently 14 15 24 i want it in one array which i register to like whereArray[n] ="14,15 ,24" like this now i get this splited as whereArray[n1]=14 whereArray[n1]=15 whereArray[n1]=24 – Ashish Shukla Jan 23 '20 at 08:52
  • @damien-the-unbeliever can u tell or suggest how could i do that – Ashish Shukla Jan 23 '20 at 08:53
  • Do your splitted values need to keep the quotes? – AsheraH Jan 23 '20 at 09:20
  • @AsheraH nope i dont need the quotes – Ashish Shukla Jan 23 '20 at 09:28

2 Answers2

0

You can use a RegEx with a capture group to keep all content between " ". For example using this pattern:

".+?"

Please read regular expressions groups in c# question if you want a code example.

ganchito55
  • 3,559
  • 4
  • 25
  • 46
  • i used this regex "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)" , but i still left with this kind of string with me *" \" myCharacter "* so i run i loop and i remove the \" by whereArray[i].Remove(0, 2); so for now it worked..i am finding more better way! – Ashish Shukla Jan 24 '20 at 06:03
0

i used this regex "(?:^|,)(\"(?:[^\"]+|\"\")\"|[^,])" , but i still left with this kind of string with me " \" myCharacter " so i run i loop and i remove the \" by whereArray[i].Remove(0, 2); so for now it worked..i am finding more better way!

Ashish Shukla
  • 129
  • 1
  • 10