Split string and trim every element

后端 未结 5 1016
失恋的感觉
失恋的感觉 2021-02-01 14:39

Is there any library API or regex pattern to split a String on some delimiter and automatically trim leading and trailing spaces from every element without having to loop the el

5条回答
  •  名媛妹妹
    2021-02-01 15:10

    Just trim it before you split

    " A B # C#D# E # ".trim().split("\\s*#\\s*")
    

    The spaces after the commas in [ A B, C, D, E] are just the way Arrays.toString prints

提交回复
热议问题