473,379 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to remove last characters of String if they contain " "

I want to remove the last characters which are " " but the number of empty characters in the end varies.

sometimes it is:

"hello "

sometimes:
"hello "

sometimes:
"hello "
Jun 23 '22 #1
3 15300
cactusdata
214 Expert 128KB
Expand|Select|Wrap|Line Numbers
  1. InputText = "Hello  "
  2. CleanedText = RTrim(InputText)
  3.  
  4. ' CleanedTect -> "Hello"
Jun 24 '22 #2
sakshijn
2 2Bits
Remove Last Characters Of String using pop_back();

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.    string str;
  6.    cin >> str;
  7.    cout<<"Original String: "<<str<<endl;
  8.    str.pop_back();
  9.    cout<<"Required String: "<<str<<endl;
  10.    return 0;
  11. }

Remove Last Characters Of String using substr();

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.    string str;
  5.    cin >> str;
  6.    cout<<"Original String: "<<str<<endl;
  7.    cout<<"Required String: "<<str.substr(0, str.size() - 1)<<endl;
  8.    return 0;
  9. }
Jun 27 '22 #3
Anushka00
1 Bit
In python you can use the strip() method. For example :
Expand|Select|Wrap|Line Numbers
  1. name = " hello "
  2. print(name.strip())
  3.  
The output of the code will be: hello
Jul 12 '22 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
5
by: brckcc | last post by:
Sometimes when I view my string variables in the watch window, it shows an @ symbol preceding the value. Other times, I don't see the @ symbol. What does this mean?
6
by: Ole Hanson | last post by:
Hi I am wondering if there is any programmatic difference between the String.Empty and the "" for declaring an empty string? Furthermore, is there any performance penalty by doing the one over...
6
by: G. | last post by:
This is an obvious bug in the String.Replace function: //load a XML string into a document XmlDocument doc = new XmlDocument(); doc.LoadXml("<test id='' />"); //Obtain the string...
4
by: michi | last post by:
Hello How can I convert a string to double with a decimal point as seperator? ***CODE**** strNumber ="12.00" dblDouble = Cdbl(strNumber) ****
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
9
by: CeyloR | last post by:
Can anyone tell me what the "c" means in a statement like this: strTest = New String(" "c,10) I know the 10 in above example stands for the maxlength of characters in the string. Is it posible...
6
by: Charlie | last post by:
Hi: Is there any difference between string.Empty and String.Empty? And what is the benefit of using it over "". Thanks, Charlie
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
1
by: Lawrence Lichte | last post by:
Whay can't I end a string assignment with the '\'.... fylpath = "c:\scripts\python\prod_select\" the last '\' isn't included in the string when I print the string. I was using the string to define...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.