Java: splitting a comma-separated string but ignoring commas in quotes

前端 未结 11 1538
广开言路
广开言路 2020-11-21 05:16

I have a string vaguely like this:

foo,bar,c;qual=\"baz,blurb\",d;junk=\"quux,syzygy\"

that I want to split by commas -- but I need to igno

11条回答
  •  一向
    一向 (楼主)
    2020-11-21 06:11

    I would do something like this:

    boolean foundQuote = false;
    
    if(charAtIndex(currentStringIndex) == '"')
    {
       foundQuote = true;
    }
    
    if(foundQuote == true)
    {
       //do nothing
    }
    
    else 
    
    {
      string[] split = currentString.split(',');  
    }
    

提交回复
热议问题