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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:04:48+00:00 2026-05-15T10:04:48+00:00

Problem: If String ends with \r, remove \r I started with something like this

  • 0

Problem:
If String ends with \r, remove \r

I started with something like this

if (masterValue.endsWith(CARRIAGE_RETURN_STR)) {
  masterValue = masterValue.replace(CARRIAGE_RETURN_STR, "");
}

where

public static final String CARRIAGE_RETURN_STR = (Character.toString(Constants.CARRIAGE_RETURN));
public static final char CARRIAGE_RETURN = '\r';

This seems awkward to me.

Is there an easy way to just remove \r character?

I then moved on to this:

if (value.contains(CARRIAGE_RETURN_STR)) {
   value = value.substring(0, value.length()-3);

//-3 because we start with 0 (1), line ends with \n (2) and we need to remove 1 char (3)

But this too seems awkward .

Can you suggest a easier, more elegant solution?

  • 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-15T10:04:48+00:00Added an answer on May 15, 2026 at 10:04 am

    Regexes can support end-of-string anchoring, you know. (See this Javadoc page for more information)

    myString.replaceAll("\\r$", "");
    

    This also takes care of fixing \r\n –> \n, I believe.

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

Sidebar

Related Questions

Problem: When I do something like this: for (int i = 0; i <
Attempting something like public string MyText { get {return lbl.Text;} set {lbl.Text = value;}}
I have a string in javascript like this: some string 27 or it could
I have an input string like this: \pard\nowidctlpar\qj\b0\scaps This Agreement\scaps0 is made and entered
I've got a strange problem using the Castle NVelocity... If the template string ends
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
Sometimes i face the following problem : string txt = con.Request.Params[Par_name].ToString();//the original par value
I am encountering a problem with string formatting while trying to get only the
I am using LaTeX and I have a problem concerning string manipulation. I want
Hello I have a problem with trimming string in c++. It adds some weird

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.