473,243 Members | 1,599 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,243 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 15201
cactusdata
213 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
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.