trim

javascript need to do a right trim

安稳与你 提交于 2019-12-03 01:10:32
In javascript, how to I do a right trim? I have the following: var s1 = "this is a test~"; var s = s1.rtrim('~') but was not successful Use a RegExp. Don't forget to escape special characters. s1 = s1.replace(/~+$/, ''); //$ marks the end of a string // ~+$ means: all ~ characters at the end of a string You can modify the String prototype if you like. Modifying the String prototype is generally frowned upon, but I personally prefer this method, as it makes the code cleaner IMHO. String.prototype.rtrim = function(s) { return this.replace(new RegExp(s + "*$"),''); }; Then call... var s1 = "this

How to delete specific characters from a string in Ruby?

走远了吗. 提交于 2019-12-02 18:40:30
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? Arup Rakshit Do as below using String#tr : "((String1))".tr('()', '') # => "String1" If you just want to remove the first two characters and the last two, then you can use negative indexes on the string: s = "((String1))" s = s[2...-2] p s # => "String1" If you want to remove all parentheses from the string you can use the delete method on the string class: s = "((String1))" s.delete! '()' p s # => "String1" Using String#gsub with

Bash parameter expansion works only in interactive shell, but not in script

旧巷老猫 提交于 2019-12-02 17:48:51
问题 In user's console I have bash : $ echo $SHELL /bin/bash $ bash --version GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu) I have code in file test.sh: $ cat test.sh aaa='---aa-aa---' echo "${aaa}" echo 'does not work...' # trim "-" echo ${aaa/+(-)} echo ${aaa%%+(-)} echo 'works for one symbol...' echo ${aaa%-} echo ${aaa/-} The last two rows work fine but previous ones. $ bash test.sh ---aa-aa--- does not work... ---aa-aa--- ---aa-aa--- works for one symbol... ---aa-aa-- --aa-aa-

Cut end of multiple videos

隐身守侯 提交于 2019-12-02 17:26:35
问题 I need a script to cut off the last 6 seconds of multiple videos. The videos do all have different length. I can‘t find anything helpful online. Does anyone know how to do that? thx 回答1: A method that uses ffprobe to get the input duration, bc to calculate the desired output duration, and ffmpeg to perform the cutting. This method does not require the inputs to contain an audio stream, but it requires two additional tools ( ffprobe and bc ) instead of just ffmpeg . Your preferred scripting

Trim whitespace from a String

北战南征 提交于 2019-12-02 17:12:54
I know there are several ways to do this in Java and C that are nice, but in C++ I can't seem to find a way to easily implement a string trimming function. This is what I currently have: string trim(string& str) { size_t first = str.find_first_not_of(' '); size_t last = str.find_last_not_of(' '); return str.substr(first, (last-first+1)); } but whenever I try and call trim(myString); I get the compiler error /tmp/ccZZKSEq.o: In function `song::Read(std::basic_ifstream<char, std::char_traits<char> >&, std::basic_ifstream<char, std::char_traits<char> >&, char const*, char const*)': song.cpp:(

How many spaces will Java String.trim() remove?

帅比萌擦擦* 提交于 2019-12-02 16:26:51
In Java, I have a String like this: " content ". Will String.trim() remove all spaces on these sides or just one space on each? LukeH All of them . Returns : A copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space. ~ Quoted from Java 1.5.0 docs (But why didn't you just try it and see for yourself?) From the source code (decompiled) : public String trim() { int i = this.count; int j = 0; int k = this.offset; char[] arrayOfChar = this.value; while ((j < i) && (arrayOfChar[(k + j)] <= ' ')) ++j; while ((j < i) &&

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

陌路散爱 提交于 2019-12-02 15:32:47
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 a performance degradation if i call trim function recursivelly in a loop using a function. I heard regexp_replace can match the whitespaces and remove them. Can you guide of a reliable way to use regexp_replace to trim multiple tabspaces or new lines or combinations of them in beginning and end of a String. If there is any other way, Please guide

How can I trim all strings in an Array? [duplicate]

巧了我就是萌 提交于 2019-12-02 14:15:44
This question already has an answer here: How to trim white spaces of array values in php 11 answers If I have this array: array(" hey ", "bla ", " test"); and I want to trim all of them, How can I do that? The array after the trim: array("hey", "bla", "test"); array_map() is what you need: $result = array_map('trim', $source_array); array_map() applies a given callback to every value of an array and return the results as a new array. $array = array_map('trim', $array); 来源: https://stackoverflow.com/questions/6769464/how-can-i-trim-all-strings-in-an-array

Bash parameter expansion works only in interactive shell, but not in script

。_饼干妹妹 提交于 2019-12-02 09:39:20
In user's console I have bash : $ echo $SHELL /bin/bash $ bash --version GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu) I have code in file test.sh: $ cat test.sh aaa='---aa-aa---' echo "${aaa}" echo 'does not work...' # trim "-" echo ${aaa/+(-)} echo ${aaa%%+(-)} echo 'works for one symbol...' echo ${aaa%-} echo ${aaa/-} The last two rows work fine but previous ones. $ bash test.sh ---aa-aa--- does not work... ---aa-aa--- ---aa-aa--- works for one symbol... ---aa-aa-- --aa-aa--- In the same time, if you would try to make this console it works: $ aaa='---aa-aa---' $ echo ${aaa/+

How to trim audio file in iPhone?

自闭症网瘾萝莉.ら 提交于 2019-12-02 07:08:31
I have sound files in my document directory folder and i want to trim that sound file. How to do that? you can use Extended Audio File Services. have a look at the reference for ExtAudioFileRead & ExtAudioFileWrite (they have sample code) then you can open one audio file read it, trim it and then write the new one.go here http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/ExtendedAudioFileServicesReference/Reference/reference.html Dumb Code What do you mean by trim ? You want to get chunk for aduio of specific duration from with in main Audio file ? might be this post