trim

Replace multiple whitespaces with single whitespace in JavaScript string

回眸只為那壹抹淺笑 提交于 2019-11-26 11:09:59
I have strings with extra whitespaces, each time there's more than only one whitespace I'd like it be only one. Anyone? I tried searching google, but nothing worked for me. Thanks bjornd Something like this: var s = " a b c "; console.log( s.replace(/\s+/g, ' ') ) You can augment String to implement these behaviors as methods, as in: String.prototype.killWhiteSpace = function() { return this.replace(/\s/g, ''); }; String.prototype.reduceWhiteSpace = function() { return this.replace(/\s+/g, ' '); }; This now enables you to use the following elegant forms to produce the strings you want: "Get

Replace multiple whitespaces with single whitespace in JavaScript string

断了今生、忘了曾经 提交于 2019-11-26 11:06:41
I have strings with extra whitespaces, each time there's more than only one whitespace I'd like it be only one. Anyone? I tried searching google, but nothing worked for me. Thanks bjornd Something like this: var s = " a b c "; console.log( s.replace(/\s+/g, ' ') ) You can augment String to implement these behaviors as methods, as in: String.prototype.killWhiteSpace = function() { return this.replace(/\s/g, ''); }; String.prototype.reduceWhiteSpace = function() { return this.replace(/\s+/g, ' '); }; This now enables you to use the following elegant forms to produce the strings you want: "Get

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

被刻印的时光 ゝ 提交于 2019-11-26 10:56:18
问题 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? 回答1: Since JDK 11 If you are on JDK 11 or higher you should probably be using stripTrailing(). Earlier JDK versions Using the regular expression \s++$ , you can replace all trailing space characters (includes space and tab characters) with the empty string ( "" ). final String text = " foo "; System.out.println(text.replaceFirst("\\s++$", ""));

Difference between String trim() and strip() methods in Java 11

心不动则不痛 提交于 2019-11-26 10:48:26
问题 Among other changes, JDK 11 introduces 6 new methods for java.lang.String class: repeat(int) - Repeats the String as many times as provided by the int parameter lines() - Uses a Spliterator to lazily provide lines from the source string isBlank() - Indicates if the String is empty or contains only white space characters stripLeading() - Removes the white space from the beginning stripTrailing() - Removes the white space from the end strip() - Removes the white space from both, beginning and

Android sdk cut/trim video file

*爱你&永不变心* 提交于 2019-11-26 10:32:35
问题 Is there any way to cut a video (mp4 or 3gp) on android, like use only the last 5 seconds of the movie... on iphone this is possible using the AVAssetExportSession but on android I haven\'t found anything similar, just maybe some references to ffmpeg library which seems complicated. Is there any easier way to do it? 回答1: You can do this with my mp4parser library. Have a look at the ShortenExample it does exactly what the name suggests. Since the library cannot re-encode the video it can only

How to remove whitespace from right end of NSString?

烈酒焚心 提交于 2019-11-26 09:50:31
问题 This removes white space from both ends of a string: NSString *newString = [oldString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; How do I remove white space from just the right end of a string? UPDATE: The code from the accepted answer is now part of SSToolkit. Yay! 回答1: UPDATE: A quick benchmark showed that Matt's own adaption, based on Max' & mine, performs best. @implementation NSString (TrimmingAdditions) - (NSString *

Strip / trim all strings of a dataframe

耗尽温柔 提交于 2019-11-26 09:27:50
问题 Cleaning the values of a multitype data frame in python/pandas, I want to trim the strings. I am currently doing it in two instructions : import pandas as pd df = pd.DataFrame([[\' a \', 10], [\' c \', 5]]) df.replace(\'^\\s+\', \'\', regex=True, inplace=True) #front df.replace(\'\\s+$\', \'\', regex=True, inplace=True) #end df.values This is quite slow, what could I improve ? 回答1: You can use DataFrame.select_dtypes to select string columns and then apply function str.strip. Notice: Values

iOS Audio Trimming

孤街浪徒 提交于 2019-11-26 09:25:47
问题 I searched a lot and couldn\'t find anything relevant... I am working on iOS audio files and here is what I want to do... Record Audio and Save Clip (Checked, I did this using AVAudioRecorder ) Change the pitch (Checked, Did this using Dirac) Trimming :( I have two markers i.e. starting & ending offset and using this info I want to trim recorded file and want to save it back. I don\'t want to use \"seek\" because later on I want to play all recorded files in sync (just like flash movie clips

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

纵然是瞬间 提交于 2019-11-26 09:18:59
问题 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 Underscore (_) character. For example: ABC DEFGH IJKLMNOP The SUBSTRING function doesn\'t seem to be up to the task because it is position-based and the position of the underscore varies. I thought about the TRIM function (the RTRIM function specifically):

How do I remove leading whitespace in Python?

断了今生、忘了曾经 提交于 2019-11-26 08:48:01
问题 I have a text string that starts with a number of spaces, varying between 2 & 4. What is the simplest way to remove the leading whitespace? (ie. remove everything before a certain character?) \" Example\" -> \"Example\" \" Example \" -> \"Example \" \" Example\" -> \"Example\" 回答1: The lstrip() method will remove leading whitespaces, newline and tab characters on a string beginning: >>> ' hello world!'.lstrip() 'hello world!' Edit As balpha pointed out in the comments, in order to remove only