Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reg expression question  RSS feed

 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,

I am new to Java reg expressions, but this looks like a good case to use them. I am getting a string that sometimes has multiple values seperated by commas. So For example I might get "Value1, Value2, Value3". Or it might just conatain one value with no commas. Like "Value1". It looks like the String class has a methods that takes a regex and the string and returns a String[]. So I am wondering if it is just one value will it return that one? Does anyone have an example?

Thanks,

AMD
 
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
I am assuming that you mean the split() method? Yes, if you provide a delimiter that doesn't exist, and the original string is not zero length, it will return an array of size one, with the original value.

Henry
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice thanks

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