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
113
votes
9 answers

Remove last specific character in a string c#

I use WinForms c#.I have string value like below, string Something = "1,5,12,34,"; I need to remove last comma in a string. So How can i delete it ?
user3042186
  • 1,197
  • 3
  • 8
  • 8
103
votes
5 answers

IE8 and JQuery's trim()

I am making use of trim() like so: if($('#group_field').val().trim()!=''){ Where group_field is an input element of type text. This works in Firefox but when I try it on IE8 it gives me this error: Message: Object doesn't support this property or…
Abs
  • 56,052
  • 101
  • 275
  • 409
103
votes
6 answers

How to delete specific characters from a string in Ruby?

I have several strings that look like this: "((String1))" They are all different lengths. How could I remove the parentheses from all these strings in a loop?
Cristiano
  • 2,839
  • 8
  • 25
  • 35
101
votes
9 answers

How to remove new line characters from data rows in mysql?

I can loop through all of the rows in a php script and do UPDATE mytable SET title = "'.trim($row['title']).'" where id = "'.$row['id'].'"; and trim can remove \n But I was just wondering if something same could be done in one query? update…
TigerTiger
  • 10,590
  • 15
  • 57
  • 72
99
votes
12 answers

Javascript - Apply trim function to each string in an array

Want to trim each string in an array, e.g., given x = [' aa ', ' bb ']; output ['aa', 'bb'] My first trial is x.map(String.prototype.trim.apply) It got "TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a…
neuront
  • 9,312
  • 5
  • 42
  • 71
97
votes
5 answers

How to extend C# built-in types, like String?

I need to Trim a String. But I want to remove all the repeated blank spaces within the String itself, not only at the end or at the start of it. I could do it with a method like: public static string ConvertWhitespacesToSingleSpaces(string value) { …
Girardi
  • 2,734
  • 3
  • 35
  • 50
92
votes
6 answers

Removing spaces from string

I'm trying to remove all the spaces from a string derived from user input, but for some reason it isn't working for me. Here is my code. public void onClick(View src) { switch (src.getId()) { case R.id.buttonGo: String input…
Slicekick
  • 2,119
  • 5
  • 24
  • 35
86
votes
8 answers

How to Select a substring in Oracle SQL up to a specific character?

Say I have a table column that has results like: ABC_blahblahblah DEFGH_moreblahblahblah IJKLMNOP_moremoremoremore I would like to be able to write a query that selects this column from said table, but only returns the substring up to the…
Pretzel
  • 8,141
  • 16
  • 59
  • 84
82
votes
14 answers

Trim characters in Java

How can I trim characters in Java? e.g. String j = “\joe\jill\”.Trim(new char[] {“\”}); j should be "joe\jill" String j = “jack\joe\jill\”.Trim("jack"); j should be "\joe\jill\" etc
Quintin Par
  • 15,862
  • 27
  • 93
  • 146
82
votes
12 answers

trim all strings in an array

I have a string that comes in like: string email = "a@a.com, b@b.com, c@c.com"; I want to split it into an array of strings If I do this: string[] emails = email.Split(','); I get spaces in front of each email address (after the first…
leora
  • 188,729
  • 360
  • 878
  • 1,366
79
votes
12 answers

How to remove the extra spaces in a string?

What function will turn this contains spaces into this contains spaces using javascript? I've tried the following, using similar SO questions, but could not get this to work. var string = " this contains spaces "; newString =…
d-_-b
  • 21,536
  • 40
  • 150
  • 256
71
votes
5 answers

Trim to remove white space

jQuery trim not working. I wrote the following command to remove white space. Whats wrong in it? var str = $('input').val(); str = jquery.trim(str); console.log(str); Fiddle example.
Akhil K Nambiar
  • 3,835
  • 13
  • 47
  • 85
70
votes
3 answers

How to remove whitespace from a string in typescript?

In my angular 5 project, with typescript I am using the .trim() function on a string like this, But it is not removing the whitespace and also not giving any error. this.maintabinfo = this.inner_view_data.trim().toLowerCase(); // inner_view_data…
67
votes
6 answers

Trim leading or trailing characters from a string?

How can I trim the leading or trailing characters from a string in java? For example, the slash character "/" - I'm not interested in spaces, and am looking to trim either leading or trailing characters at different times.
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
67
votes
8 answers

Perform Trim() while using Split()

today I was wondering if there is a better solution perform the following code sample. string keyword = " abc, foo , bar"; string match = "foo"; string[] split= keyword.Split(new char[] { ',', ';' },…
citronas
  • 19,035
  • 27
  • 96
  • 164