Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:11:43+00:00 2026-05-30T01:11:43+00:00

I can’t get these examples from the SUN tutorial of String split : E.g.

  • 0

I can’t get these examples from the SUN tutorial of String split:

E.g. for "boo:and:foo"

Regex   Limit   Result  

o   5   { "b", "", ":and:f", "", "" }  
o   -2  { "b", "", ":and:f", "", "" }  
o   0   { "b", "", ":and:f" }  

I can’t understand the result.
I read that for negative limit the pattern is applied as many times as possible and for positive limit it is applied n-1 times etc.

But I can’t understand how the resulting array is formed in each case.

E.g. in first case why we have 1 “” in location 1 but 2 “” in locations 3 and 4?
Same for the rest.

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:11:44+00:00Added an answer on May 30, 2026 at 1:11 am

    Let’s start by understanding all possible splits. I think "b" and ":and:f" are clear.

    The empty strings came from splitting between o‘s (fo-""-o,bo-""-o), and splitting after the last o – until the end of the string, which is again – an empty strng.

    So totally we have 5 matching strings that the split can return.

    If we split using 5 – we return at most 5 substrings, whcih is exactly the 5 substrings we have, resulting in the first output:

    If the limit n is greater than zero then the pattern will be applied
    at most n – 1 times, the array’s length will be no greater than n, and
    the array’s last entry will contain all input beyond the last matched
    delimiter

    If we split using -2, we return as much as possible [which is identical to 5 in this case]:

    If n is non-positive then the pattern will be applied as many times as
    possible and the array can have any length

    If we split using 0, we return as much as possible – but we discard al the trailing empty strings:

    If n is zero then the pattern will be applied as many times as
    possible, the array can have any length, and trailing empty strings
    will be discarded

    Note: If you want to ignore the empty strings between occurances of o, you should split with the regex "o+" – which takes as much o‘s as possible, thus resulting in no empty strings from between o‘s

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I get a 'when to use' for these and others? <% %> <%#
Does anyone know how can I replace this 2 symbol below from the string
Can someone give me example how to parse mixed feed result from google api
Can you cast a List<int> to List<string> somehow? I know I could loop through
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can i get the source code for a WAMP stack installer somewhere? Any help
Can some one Guide me to work with these things... What is Model popup
can someone show me the regex for this preg_match. I want to make sure
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can someone tell me the regex to see if something is surrounded in double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.