This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Split problem  RSS feed

 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have fields that look like this: "M|F".

I want to split that String on the "|". However, it doesn't seem to work when I run the following code:



The result I get is every character (M, |, and F) is in its own array index. What am I doing wrong?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "|" has special meaning in a regex -- it is a OR operation for search patterns. If you actually want the literal "|", then you need to escape it as "\\|".

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!