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

regular expression  RSS feed

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dear friends,
When i execute the above code the caret count is 8.
Its not taking two continuous carets into count.
How to make the program to count continuous carets also?

Kindly provide your help.
Regards,
Vijay
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only get 8 Strings because there is no String to get between �^^�. If you only want to count the number of �^� in the String you will need to take another approach.

Which is the specific task you have to accomplish with your program� maybe by knowing somewhat more it will be easier to understand your problem.
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your reply Jaime!!

My problem is, i want to count the number of carets in a String and based on the number of carets i have to validate some functionality.

The caret count is fixed and it should/must be equal to 9.
So i want the caret to be counted even if they are present continuously.

This is my problem.
Hope this is clear to you Jaime.

Thanks & Regards,
Vijay
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaime Tovar:
You only get 8 Strings because there is no String to get between “^^”.

The problem is not that they're contiguous, it's that they're at the end of the string; split() ignores trailing empty fields by default. To override that behavior, use the two-argument form of split with -1 as second argument: That will give you an array of length 10 in which the last two elements are empty strings. Be aware that 10, not 9, is the number you'll get by iterating over the array, which is unnecssary anyway. If you really want to know how many separators there are, all you have to do is subtract 1 from the array's length:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!