473,383 Members | 1,742 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,383 software developers and data experts.

How to trim the characters at the end of the number?

440 256MB
Hi,

I have a number which is read from the file and the termination of that line is done by "," comma.When I read this number while parsing the file,I get the number as shown below

"1000,"

But I need only "1000" value.How to get rid of the "," from the read number. or is there any way to get rid of the line delimiter while reading the file data.

Could anbody help me in solving this issue

Thanks in advance
PSB
Mar 3 '07 #1
4 1746
ghostdog74
511 Expert 256MB
Hi,

I have a number which is read from the file and the termination of that line is done by "," comma.When I read this number while parsing the file,I get the number as shown below

"1000,"

But I need only "1000" value.How to get rid of the "," from the read number. or is there any way to get rid of the line delimiter while reading the file data.

Could anbody help me in solving this issue

Thanks in advance
PSB
if the comma is at end of line, just use strip()
Expand|Select|Wrap|Line Numbers
  1. >>> a = "sdfsdf,"
  2. >>> a.strip(",")
  3. 'sdfsdf'
  4. >>>    
  5.  
pls read the docs.
Mar 3 '07 #2
Thekid
145 100+
What about this:

Expand|Select|Wrap|Line Numbers
  1. >>>a = "1000,"
  2. >>>print a [:-1] 
  3. 1000
  4.  
  5.  
Mar 5 '07 #3
ghostdog74
511 Expert 256MB
What about this:

Expand|Select|Wrap|Line Numbers
  1. >>>a = "1000,"
  2. >>>print a [:-1] 
  3. 1000
  4.  
  5.  
it can be done but it will strip every last character. it will not work if data is like this
eg
1000,
20000,
3000
40000,

"3000" will become 300
Mar 5 '07 #4
Thekid
145 100+
it can be done but it will strip every last character. it will not work if data is like this
eg
1000,
20000,
3000
40000,

"3000" will become 300
I see what you're saying ghostdog74. I was under the impression he wanted a single character removed from the end of a printed line:
1, 25, 78, 345, 672, 1000,
Mar 6 '07 #5

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

Similar topics

1
by: Shabam | last post by:
Is there a function in dotnet that allows me to trim user input so that: 1) It gets rid of leading/trailing spaces, tabs, newlines and whatever other non-printing characters 2) Gets rid of all...
3
by: jose luis fernandez diaz | last post by:
Hi, Does any know a algorithm to strip heading and leading blank in a string ? Tnansk, Jose Luis
22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
3
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two...
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
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...
7
by: Sascha Herpers | last post by:
Hi, what is the difference between the trim function and the trim String-member? As far as I see it, both return the trimmed string and leave the original string unaltered. Is any of the two...
3
by: | last post by:
I'm just trying to strip non numeric characters out of a string (phone number) and the following snippet isn't working. It's pretty straight forward and should working according to:...
4
by: Oleg Subachev | last post by:
If I apply Trim() method to string consisting of two x0D and x0A characters the resulting string is not empty but contain the same two charaters: x0D, x0A. But according to the help Trim()...
121
by: swengineer001 | last post by:
Just looking for a few eyes on this code other than my own. void TrimCString(char *str) { // Trim whitespace from beginning: size_t i = 0; size_t j; while(isspace(str)) {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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.