Questions tagged [trim]

Trimming refers to the manipulation of a text string to remove leading and/or trailing whitespace (and/or ASCII control characters), or (optionally) a specified character.

2454 questions
65
votes
13 answers

In Haskell, how do you trim whitespace from the beginning and end of a string?

How do you trim whitespace from the start and end of a string? trim " abc " => "abc" Edit: Ok, let me be a little clearer. I did not understand that string literals were treated so differently from Strings. I would like to do this: import…
Eric Normand
  • 3,806
  • 1
  • 22
  • 26
59
votes
7 answers

What is a good alternative of LTRIM and RTRIM in Java?

What is a good alternative of JavaScript ltrim() and rtrim() functions in Java?
yegor256
  • 102,010
  • 123
  • 446
  • 597
53
votes
2 answers

How to Trim "[" char from a string in Golang

Probably a silly thing but got stuck on it for a bit... Can't trim a "[" char from a string, things I tried with outputs: package main import ( "fmt" "strings" ) func main() { s := "this[things]I would like to remove" t :=…
Blue Bot
  • 2,278
  • 5
  • 23
  • 33
51
votes
12 answers

How to select first 10 words of a sentence?

How do I, from an output, only select the first 10 words?
AAA
  • 3,120
  • 11
  • 53
  • 71
51
votes
10 answers

How to remove only trailing spaces of a string in Java and keep leading spaces?

The trim() function removes both the trailing and leading space, however, if I only want to remove the trailing space of a string, how can I do it?
kzjfr0
  • 533
  • 1
  • 4
  • 8
49
votes
5 answers

Trim trailing spaces with PostgreSQL

I have a column eventDate which contains trailing spaces. I am trying to remove them with the PostgreSQL function TRIM(). More specifically, I am running: SELECT TRIM(both ' ' from eventDate) FROM EventDates; However, the trailing spaces don't go…
zgall1
  • 2,865
  • 5
  • 23
  • 39
48
votes
3 answers

How do you trim the audio file's end using SoX?

Using Sox, how do I shorten an audio file by 5 seconds, trimming from the end? For example, this is how to trim a file from the beginning: sox input output trim 5000 This is how to add 5 seconds of silence to the end: sox input output pad 0…
get8p
  • 709
  • 2
  • 8
  • 12
47
votes
10 answers

How to trim specific characters from the end of the JavaScript string?

In JavaScript, how do I trim from the right(string end)? I have the following example: var s1 = "this is a test~"; var s = s1.rtrim('~');
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
47
votes
10 answers

Trim string column in PySpark dataframe

After creating a Spark DataFrame from a CSV file, I would like to trim a column. I've tried: df = df.withColumn("Product", df.Product.strip()) df is my data frame, Product is a column in my table. But I get the error: Column object is not…
minh-hieu.pham
  • 1,029
  • 2
  • 12
  • 21
45
votes
10 answers

Remove '\' char from string c#

I have the following code string line = ""; while ((line = stringReader.ReadLine()) != null) { // split the lines for (int c = 0; c < line.Length; c++) { if ( line[c] == ',' && line[c - 1] == '"' && line[c + 1] == '"') …
maffo
  • 1,393
  • 4
  • 18
  • 35
45
votes
3 answers

Php how to remove any last commas

Example output 1. test,test,test,test,test, 2. test,test,test,, 3. test,test,,, 4. test,,,,, I tried use implode according to my previous question but It's trim only last comma. How to remove any last commas?
wow
  • 7,989
  • 17
  • 53
  • 63
44
votes
8 answers

Cocoa - Trim all leading whitespace from NSString

(have searched, but not been able to find a simple solution to this one either here, or in Cocoa docs) Q. How can I trim all leading whitespace only from an NSString? (i.e. leaving any other whitespace intact.) Unfortunately, for my purposes,…
SirRatty
  • 2,338
  • 5
  • 25
  • 37
44
votes
5 answers

What's the meaning of 'trim' when use in mongoose?

The link is http://mongoosejs.com/docs/api.html#schema_string_SchemaString-trim I'm beginner in mongoosejs. I just don't get it... I saw this question How to update mongoose default string schema property trim? but don't understand why trim. Im…
Undefined Behavior
  • 2,128
  • 4
  • 24
  • 34
44
votes
19 answers

How to trim() white spaces from a string?

JavaScript doesn't seem to have a native trim() method. How can I trim white spaces at the start and end of a string with JavaScript?
MDCore
  • 17,583
  • 8
  • 43
  • 48
43
votes
17 answers

How to remove trailing and leading whitespace for user-provided input in a batch file?

I know how to do this when the variable is pre-defined. However, when asking for the user to enter in some kind of input, how do I trim leading and trailing whitespace? This is what I have so far: @echo off set /p input=: echo. The input is %input%…
OopOop
  • 433
  • 1
  • 4
  • 4