trim

JavaScript trim line breaks with regex?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 01:53:44
问题 I am using Google Translate to translate the contents of a textarea and fill another textarea with the API response. In my source textarea I am replacing the /n newlines with <br /> line breaks to send the query like this: var query = $('#textarea-src').val(); var query = encodeURIComponent(query); var query = query.replace(/\n\r?/g, '<br />'); // replace new lines with line breaks Then I make the call to Google: $.ajax({ url: apiUrl, dataType: 'jsonp', success: function(data) { var response

How to trim all leading/trailing <br> code using php

纵饮孤独 提交于 2019-12-02 00:21:32
问题 I am trying to remove all leading and trailing <br> in a string using PHP. Here is an example <br><br> Hello<br> World<br> <p>This is a message<br>...</p> <br><br><br><br> I want to return Hello<br> World<br> <p>This is a message<br>...</p> I tried to do the following echo trim($str, '<br>'); But it does not remove them. How can I remove the new line html code? 回答1: Use preg_replace with the beginning ^ and end $ anchors: $string = preg_replace('/^(<br>){0,}|(<br>){0,}$/', '', $string); Or

How to trim all leading/trailing <br> code using php

删除回忆录丶 提交于 2019-12-01 22:22:02
I am trying to remove all leading and trailing <br> in a string using PHP. Here is an example <br><br> Hello<br> World<br> <p>This is a message<br>...</p> <br><br><br><br> I want to return Hello<br> World<br> <p>This is a message<br>...</p> I tried to do the following echo trim($str, '<br>'); But it does not remove them. How can I remove the new line html code? Use preg_replace with the beginning ^ and end $ anchors: $string = preg_replace('/^(<br>){0,}|(<br>){0,}$/', '', $string); Or for multiple lines: $string = preg_replace('/^(<br>){0,}|(<br>){0,}$/m', '', $string); You could also trim()

Trimming new line character from a string in java

纵然是瞬间 提交于 2019-12-01 22:05:12
问题 The output of below program: public class TestClass { public static void main(final String[] args){ String token = "null\n"; token.trim(); System.out.println("*"); System.out.println(token); System.out.println("*"); } } is: * null * However How to remove newlines from beginning and end of a string (Java)? says otherwise. What am I missing? 回答1: Since String is immutable token.trim(); doesn't change the underlying value, it returns a new String without the leading and ending whitespace

Trimming new line character from a string in java

别等时光非礼了梦想. 提交于 2019-12-01 19:44:47
The output of below program: public class TestClass { public static void main(final String[] args){ String token = "null\n"; token.trim(); System.out.println("*"); System.out.println(token); System.out.println("*"); } } is: * null * However How to remove newlines from beginning and end of a string (Java)? says otherwise. What am I missing? Since String is immutable token.trim(); doesn't change the underlying value, it returns a new String without the leading and ending whitespace characters. You need to replace your reference token = token.trim(); Strings are immutable. Change token.trim(); to

Trim &nbsp values in javascript

余生长醉 提交于 2019-12-01 17:27:28
问题 I am trying to trim the text which I get from kendo editor like this. var html = "  T  "; // This sample text I get from Kendo editor console.log("Actual :" + html + ":"); var text = ""; try { // html decode var editorData = $('<div/>').html(html).text(); text = editorData.trim(); console.log("After trim :" + text + ":"); } catch (e) { console.log("exception"); text = html; } This code is in seperate js file ( generated from typescript). When the page loads the trimming is not working. But

How to remove whitespace in text

人走茶凉 提交于 2019-12-01 16:52:16
问题 How can I trim a text string in my Angular application? Example {{ someobject.name }} someobject.name results in "name abc" What I like to achieve is name to be "nameabc" (remove all whitespaces). I already created a pipe and included this in the typescript file and module) PIPE: import { Pipe, PipeTransform } from "@angular/core"; @Pipe({ name: 'trim' }) export class TrimPipe implements PipeTransform { transform(value: any) { if (!value) { return ''; } return value.trim(); } } {{ someobject

Trim leading/trailing whitespace from textarea using jQuery?

*爱你&永不变心* 提交于 2019-12-01 16:39:07
Following code is an example of text placed into a textarea from a database. <textarea id="inputPane" cols="80" rows="40" class="pane"> <p> some text here... </p> <p> more text here... </p> </textarea> using jQuery's .trim what is the actual jquery code to remove all leading and trailing whitespace and have the textarea display very similar to below? <textarea id="inputPane" cols="80" rows="40" class="pane"> <p>some text here...</p> <p>more text here...</p> </textarea> I've worked on this for hours with no success trying varying combinations with .trim $('#inputPane')jQuery.trim(string); You

Algorithms to trim leading zeroes from a SQL field?

不羁的心 提交于 2019-12-01 15:15:24
I just came across the interesting problem of trying to trim the leading zeroes from a non-numeric field in SQL. (Since it can contain characters, it can't just be converted to a number and then back.) This is what we ended up using: SELECT REPLACE(LTRIM(REPLACE(fieldWithLeadingZeroes,'0',' ')),' ','0') It replaces the zeroes with spaces, left trims it, and then puts the zeroes back in. I thought this was a very clever and interesting way to do it, although not so readable if you've never come across it before. Are there any clearer ways to do this? Any more efficient ways to do this? Or any

Algorithms to trim leading zeroes from a SQL field?

馋奶兔 提交于 2019-12-01 14:13:50
问题 I just came across the interesting problem of trying to trim the leading zeroes from a non-numeric field in SQL. (Since it can contain characters, it can't just be converted to a number and then back.) This is what we ended up using: SELECT REPLACE(LTRIM(REPLACE(fieldWithLeadingZeroes,'0',' ')),' ','0') It replaces the zeroes with spaces, left trims it, and then puts the zeroes back in. I thought this was a very clever and interesting way to do it, although not so readable if you've never