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 6835441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:13:57+00:00 2026-05-26T23:13:57+00:00

Is there an easy way to trim a String based on his Offset and

  • 0

Is there an easy way to trim a String based on his Offset and Count values, that is, a function that returns OO for a String FOOBAR with an offset of 1 and a count of 2?

Obvious, one could write a simple function for this task, but I wonder if their is not a predefined Java functionality for this?

//edit: To clearify: I do mean the offset and count values defined within the given String, not external Integer values.

  • 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-26T23:13:58+00:00Added an answer on May 26, 2026 at 11:13 pm

    EDIT: Okay, now you’ve made your question clearer, it sounds like this is the scenario you’re talking about, and the solution using the String(String) constructor:

    // offset = 0, count = 6, backing array = { 'F', 'O', 'O', 'B', 'A', 'R' }
    String original = "FOOBAR";
    
    // offset = 1, count = 2, backing array = { 'F', 'O', 'O', 'B', 'A', 'R' }
    String substring = original.substring(2);
    
    // offset = 0, count = 2, backing array = { 'O', 'O' }
    String trimmed = new String(substring);
    

    Yup, substring:

    String substring = text.substring(offset, offset + count);
    

    substring takes two parameters – the “begin index” (inclusive) and the “end index” (exclusive) – hence the addition in the above code.

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

Sidebar

Related Questions

Is there an easy way to trim values in a details view during edit
Is there an easy way to convert a string that contains this: Date: Wed,
Is there an easy way to capitalize the first letter of a string and
Is there an easy way to show a formatted string representing a TimeSpan field
Is there an easy way to query a cluster for all vertices that have
Is there an easy way to use Spring IoC for a factory which returns
Is there an easy way to fetch the ManyToMany objects from a query that
Is there an easy way to iterate over an associative array of this structure
Is there an easy way in C# to create Ordinals for a number? For
Is there an easy way to produce MSDN-style documentation from the Visual Studio XML

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.