split not working correctly

前端 未结 4 850
误落风尘
误落风尘 2021-01-18 16:21

I am trying to save the groups in a string to an array so that I can use them in individual variables if I need to. For this I use split but for some reason I only

相关标签:
4条回答
  • 2021-01-18 17:09

    Just replace your line:

    ultimate_array = string_final.split("#$"); 
    

    with:

    ultimate_array = string_final.Split(new string[] { "#$" }, StringSplitOptions.None);
    

    I hope your problem is resolved...

    0 讨论(0)
  • 2021-01-18 17:10

    The split takes an regular expression and $ is a special character (end of string) so you have to escape it with backslash \. Anyway it is also special character, this time in Java, so you have to escape it also. The final code is:

    ultimate_array = string_final.split("#\\$");
    
    0 讨论(0)
  • 2021-01-18 17:14
    ultimate_array = string_final.split("#\\$");
    

    The reason your split is not working correctly is that split uses regex and "$" is a special character for regexes(drekka)

    0 讨论(0)
  • 2021-01-18 17:21

    You need to escape $ (end of string)

    ultimate_array = string_final.split("#\\$");
    
    0 讨论(0)
提交回复
热议问题