trim

How can I Trim the leading comma in my string.

I have a string that is like below. ,liger, unicorn, snipe in other languages I'm familiar with I can just do a string.trim(",") but how can I do that in c#? Thanks. There's been a lot of back and forth about the StartTrim function. As several have pointed out, the StartTrim doesn't affect the primary variable. However, given th...

Painless way to trim leading/trailing whitespace in C?

Is there a clean, preferably standard method of trimming leading and trailing whitespace from a string in C? I'd roll my own, but I would think this is a common problem with an equally common solution. ...

Is there a Perl-compatible regular expression to trim whitespace from both sides of a string?

Is there a way to do this in one line? $x =~ s/^\s+//; $x =~ s/\s+$//; In other words, remove all leading and trailing whitespace from a string. ...

What's the best way to trim std::string

I'm currently using the following code to right-trim all the std::strings in my programs: std::string s; s.erase(s.find_last_not_of(" \n\r\t")+1); It works fine, but I wonder if there are some end-cases where it might fail? Of course, answers with elegant alternatives and also left-trim solution are welcome. ...

Is there a way to use jQuery's serialize form fields and trim the value in the fields?

Hi, I have a form that uses jQuery to submit an ajax post and it serializes the form that is sent up. The code looks like this: var form = $("form"); var action = form.attr("action"); var serializedForm = form.serialize(); $.post(action, serializedForm, function(data) { ... }); The problem here is that if a field has trailing white...

Does the MySQL TRIM function not trim line breaks or carriage returns?

From my experiments, it does not appear to do so. If this is indeed true, what is the best method for removing line breaks? I'm currently experimenting with the parameters that TRIM accepts of the character to remove, starting with trimming \n and \r. ...

trimming a string in a JSTL expression

I have the following line in a JSP page: <c:if test="${postAuditBean.postAudit.authority == authority.value}"> I would like change this comparison to first trim leading and trailing spaces from both the left and right hand expressions prior to comparison... as in something like this: <c:if test="${trim(postAuditBean.postAudit.authori...

Best algorithm to strip leading and trailing spaces in C

What is the best approach in stripping leading and trailing spaces in C? ...

trim is not part of the standard c/c++ library ?

Is it me or are there no standard trim functions in the c or c++ library? is there any single function that acts as a trim? If not can anyone tell me Why trim is not part of the standard library? (i know trim is in boost) My trim code is std::string trim(const std::string &str) { size_t s = str.find_first_not_of(" \n\r\t"); siz...

Trimming a string in Python

I need to write a function in python that gets a string- If the first or last characters in the string are spaces, then they should be removed (both). If not than nothing should be done. " Hello " ----> "Hello" " Hello" -----> "Hello" "Hello " -----> "Hello" "Bob has a cat" ----> "Bob has a cat" (none of the spaces in the middle are...

VBA Trim() function truncating text oddly!

I'm trying to trim extraneous white space at the end of a memo field in MS Access. I've tried doing it a number of ways: 1) an update query with the field being updated to Trim([fieldname]). For some reason, that doesn't do anything. The whitespace is still there. 2) an update using a Macro function in which the field contents are p...

Oracle can I use scalar functions in WHERE Clause? or a NULL issue

somehow I get never any results when I call: select * from table_1 t1 where t1.c1 IS NOT NULL and trim(t1.c1) != '' ; trim(t1.c1) != '' part causes problems actually i return nothing. ...

Removing breaks from jsp

I have a function that transforms XML according to a XSLT. To test it, I'm using it in a jsp but it's entering a lot of breaks before my output. It seems to be the breaks I enter when setting variables: <c:set var="blah" value="blah" /> <c:set var="blah2" value="blah2" /> That will show two line breaks before the output. Is there a...

How do I trim these fields of quotation marks in SQL Server?

I have a table with 6 million + records, but the first field has a " at beginning and the last field has " at the end i guess when doing a bulk insert they forgot to remove it. I want to run an update query which will remove the " from those 2 fields Sample data - Field 1 "18157142 "18157152 "18157159 "18157177 "18157189 "181571...

Javascript chop/slice/trim off last character in string

I have a string 12345.00 would like it to return 12345.0 I have looked at trim but looks only to trim whitespace and slice which I don't see how this would work. Any suggs? ...

Removing starting spaces in Python?

I have a text string that starts with a number of spaces, varying between 2 & 4. What's the easiest & simplest way to remove them ie. remove everything before a certain character? Cheers! ...

Ruby : Trim New blank lines

Hi All, Please help me to solve this. This is my string str = "aaa\n\n\nbbb\n\nccc\ddd\n" means four blank lines, all together eight lines I want to return this in one line Output should be like this (aaabbbcccddd) in single line I used various trim functions to get the output but still i am failing to do it. if Anyone know the pos...

Trim leading spaces including tabs

I need to read files using vbscript and remove all leading spaces including any tabs. I now LTRIM will remove the leading spaces but how do I remove tabs also. Thanks. ...

Trim leading white space with PHP?

There seems to be a bug in a Wordpress PHP function that leaves whitespace in front of the title of the page generated by <?php echo wp_title(''); ?> I've been through the Wordpress docs and forums on that function without any luck. I'm using it this way <body id="<?php echo wp_title(''); ?>"> in order to generate an HTML body tag with...

When is it acceptable to not trim a user input string?

Can someone give me a real-world scenario of a method/function with a string argument which came from user input (e.g. form field, parsed data from file, etc.) where leading or trailing spaces SHOULD NOT have been trimmed? I can't ever recall such a situation for myself. EDIT: Mind you, I didn't say trimming any whitespace. I said trim...