• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

regular expression

 
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Skool. Stay in. Smartness. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic