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
43
votes
16 answers

Trim Whitespaces (New Line and Tab space) in a String in Oracle

I need to trim New Line (Chr(13) and Chr(10) and Tab space from the beginning and end of a String) in an Oracle query. I learnt that there is no easy way to trim multiple characters in Oracle. "trim" function trims only single character. It would be…
Seshan
  • 487
  • 1
  • 6
  • 13
42
votes
5 answers

Remove first and last char from string

I have this: $dataList = "*one*two*three*"; $list = explode("*", $dataList); echo"
";print_r($list);echo"
"; which outputs: > Array ( > [0] => > [1] => one > [2] => two > [3] => three > [4] => ) How do I strip the…
user248488
  • 435
  • 1
  • 4
  • 6
40
votes
10 answers

How do I remove trailing whitespace from a QString?

I want to remove all the trailing whitespace characters in a QString. I am looking to do what the Python function str.rstrip() with a QString. I did some Googling, and found this:…
Di Zou
  • 4,469
  • 13
  • 59
  • 88
40
votes
7 answers

How can I configure Entity Framework to automatically trim values retrieved for specific columns mapped to char(N) fields?

I'm working with a third-party database in which all text values are stored as char(n). Some of these text values are primary keys, whereas others are just normal human-readable text. For the latter, I want retrieved values to be automatically…
Sam
  • 40,644
  • 36
  • 176
  • 219
39
votes
4 answers

MySQL select fields containing leading or trailing whitespace

I can use the MySQL TRIM() method to cleanup fields containing leading or trailing whitespace with an UPDATE like so: UPDATE Foo SET field = TRIM(field); I would like to actually see the fields this will impact before this is run. I tried this but…
Michael
  • 3,568
  • 3
  • 37
  • 50
38
votes
14 answers

Best way to verify string is empty or null

i am sure this must have been asked before in different ways - as isEmptyOrNull is so common yet people implement it differently. but i have below curious query in terms of best available approach which is good for memory and performance both. 1)…
prash
  • 896
  • 1
  • 11
  • 18
36
votes
4 answers

How to use a TRIM function in SQL Server

I cannot get this TRIM code to work SELECT dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR AS [EHP Code], dbo.COL_TBL_VCOURSE.TNG_NA AS [Course Title], LTRIM(RTRIM(FCT_TYP_CD)& ') AND (' & LTRIM(RTRIM(DEP_TYP_ID) & ')' AS [Course Owner]
user1958651
  • 451
  • 1
  • 5
  • 8
32
votes
4 answers

what is this "it <= ' '" in trim string function mean here

I have this Java code to trim a string String title = titleEt.getText().toString().trim(); When I convert to kotlin, I expect this should be the kotlin code to trim the leading and trailing spaces. val title =…
lannyf
  • 9,865
  • 12
  • 70
  • 152
32
votes
1 answer

Remove all white space from string JavaScript

How can I remove all the white space from a given string. Say: var str = " abc de fog "; str.trim(); Gives abc de fog AND NOT abcdefog, which I want. How can I get all the white space removed using JavaScript?
user3566643
  • 535
  • 1
  • 4
  • 8
31
votes
8 answers

Should I trim spaces in a password field

Just wondering. We usually trim a user name in various forms in our ASP.Net application, whats the best practices for password fields. i.e. should we remove a trailing space in a password field before being saved/encrypted?
Liam
  • 1,267
  • 2
  • 17
  • 30
31
votes
4 answers

How Do I Trim Leading and Trailing Quote from MySQL Row?

I have a MySQL table that I have imported from a CSV file. In this process, a bunch of the entries have quote marks leading and trailing the entry of several data rows. For example the the table 'example_table' I have a row called 'title.' Some…
codacopia
  • 2,369
  • 9
  • 39
  • 58
31
votes
6 answers

How do I trim lines read from standard input on bash?

I want a bash way to read lines from standard input (so I can pipe input to it), and remove just the leading and trailing space characters. Piping to echo does not work. For example, if the input is: 12 s3c sd wqr the output should…
donatello
  • 5,727
  • 6
  • 32
  • 56
30
votes
8 answers

Is it possible to Trim all the values in a column in a single statement?

I've a table in a (MS) SQL database which has an Id column (identity, int) and a Name column (varchar(250)). However, the values in the name column contain (fairly random) leading and trailing spaces as I think they were cut and pasted from…
BlueChippy
  • 5,935
  • 16
  • 81
  • 131
30
votes
7 answers

Adding whitespace in Java

There is a class trim() to remove white spaces, how about adding/padding? Note: " " is not the solution.
Sobiaholic
  • 2,927
  • 9
  • 37
  • 54
30
votes
10 answers

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…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431