trim

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

别说谁变了你拦得住时间么 提交于 2019-11-27 03:49:37
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? 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++$", "")); Output foo Online demo. Here's a breakdown of the regex: \s – any whitespace character, ++ – match one or

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

旧城冷巷雨未停 提交于 2019-11-27 03:48:04
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 the end of string In particular, strip() looks very similar to trim() . As per this article strip*()

Android sdk cut/trim video file

╄→гoц情女王★ 提交于 2019-11-27 03:42:17
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? Sebastian Annies 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 cut the video at I-frames. So the points in time where you can make a cut are quite coarse.

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

◇◆丶佛笑我妖孽 提交于 2019-11-27 03:02:31
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): SELECT RTRIM('listofchars' FROM somecolumn) FROM sometable But I'm not sure how I'd get this to work

How do I remove leading whitespace in Python?

故事扮演 提交于 2019-11-27 02:43:48
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" coobird 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 spaces from the beginning of the string, lstrip(' ') should be used: >>> ' hello world with 2 spaces and a tab

Remove trailing empty space in a field content

吃可爱长大的小学妹 提交于 2019-11-27 02:21:37
问题 I am using SQL server MSDE 2000. I have a field called notes of type nvarchar(65). The content is 'Something ' with an extra space after the content (quotes for clarity) in all the records. I used the following command. UPDATE TABLE1 SET notes = RTRIM(LTRIM(notes)) But it does not work. Is there any alternate way to do it? 回答1: Are you sure the query isn't working? Try: SELECT TOP 100 '~'+ t.notes +'~' FROM TABLE1 t TOP 100 will limit the results to the first 100 rows, enough to get an idea

Fastest way to remove first char in a String

杀马特。学长 韩版系。学妹 提交于 2019-11-27 00:02:33
问题 Say we have the following string string data= "/temp string"; If we want to remove the first character / we can do by a lot of ways such as : data.Remove(0,1); data.TrimStart('/'); data.Substring(1); But, really I don't know which one has the best algorithm and doing that faster.. Is there a one that is the best or all are the same ? 回答1: The second option really isn't the same as the others - if the string is "///foo" it will become "foo" instead of "//foo". The first option needs a bit more

Do browsers remove whitespace in between text of any html tag

ε祈祈猫儿з 提交于 2019-11-26 23:14:31
问题 Here is a fiddle demonstrating the problem http://jsfiddle.net/WM8XW/ I have inserted many whitespace in the content of the label tag but the html rendered seems to remove it. Is adding   only solution to the above problem HTML Content <label>label with very long white space in between</label> 回答1: The normal behavior for the display of whitespaces is to compress them into a single one, which is then displayed. There are two exceptions from that: The <pre> tag, which keeps the whitespaces as

How can I trim beginning and ending double quotes from a string?

一曲冷凌霜 提交于 2019-11-26 22:15:42
问题 I would like to trim a beginning and ending double quote (") from a string. How can I achieve that in Java? Thanks! 回答1: You can use String#replaceAll() with a pattern of ^\"|\"$ for this. E.g. string = string.replaceAll("^\"|\"$", ""); To learn more about regular expressions, have al ook at http://regular-expression.info. That said, this smells a bit like that you're trying to invent a CSV parser. If so, I'd suggest to look around for existing libraries, such as OpenCSV. 回答2: To remove the

Remove all spaces from a string in SQL Server

浪子不回头ぞ 提交于 2019-11-26 21:31:01
What is the best way to remove all spaces from a string in SQL Server 2008? LTRIM(RTRIM(' a b ')) would remove all spaces at the right and left of the string, but I also need to remove the space in the middle. Simply replace it; SELECT REPLACE(fld_or_variable, ' ', '') Edit: Just to clarify; its a global replace, there is no need to trim() or worry about multiple spaces for either char or varchar : create table #t ( c char(8), v varchar(8)) insert #t (c, v) values ('a a' , 'a a' ), ('a a ' , 'a a ' ), (' a a' , ' a a' ), (' a a ', ' a a ') select '"' + c + '"' [IN], '"' + replace(c, ' ', '') +