trim

Removing white spaces (leading and trailing) from string value

…衆ロ難τιáo~ 提交于 2019-11-27 22:37:53
问题 I have imported a csv file in mongo using mongoimport and I want to remove leading and trailing white spaces from my string value. Is it possible directly in mongo to use a trim function for all collection or do I need to write a script for that? My collection contains elements such as: { "_id" : ObjectId("53857680f7b2eb611e843a32"), "category" : "Financial & Legal Services " } I want to apply trim function for all the collection so that "category" should not contain any leading and trailing

Remove leading zeros in batch file

百般思念 提交于 2019-11-27 22:01:03
In my application, I get a number having leading zeros. I am trying to trim the leading zeros and get the actual number. I tried using /a switch which considers right side of the assignment as an arithmetic expression. So I tried: SET /a N = 00027 The above gave me the output of 23 which is the decimal equivalent of octal number 27 . Then I found this solution online. SET N = 00027 SET /a N = 1%N%-(11%N%-1%N%)/10 This seems working and is giving the output 27 . Is there much easier way to trim the leading zeros in a batch file? The method you found is very good. It supports numbers up to 99

Trim end off of string in swift, getting error at runtime

旧街凉风 提交于 2019-11-27 19:27:34
问题 I'm making a calculator app in Swift, once my answer is obtained I want to display it in a UILabel. Only problem is I want to limit said answer to 8 characters. Here is my code: let answerString = "\(answer)" println(answer) calculatorDisplay.text = answerString.substringToIndex(advance(answerString.startIndex, 8)) This does not return any compiler errors but at runtime I get: fatal error: can not increment endIndex Any and all help would be greatly appreciated. 回答1: There are two different

Php how to remove any last commas

泄露秘密 提交于 2019-11-27 18:58:39
Example output 1. test,test,test,test,test, 2. test,test,test,, 3. test,test,,, 4. test,,,,, I tried use implode according to my previous question but It's trim only last comma. How to remove any last commas? rtrim('test,,,,,', ','); See the manual . rtrim for example: $str = 'foo,bar,blah,bleh,'; echo rtrim($str,','); // foo,bar,blah,bleh completely different way: $str = "1,2,3,4,"; $str = substr($str,0,strlen($str)-1); 来源: https://stackoverflow.com/questions/3120398/php-how-to-remove-any-last-commas

Automatically trimming an mp3 in PHP

雨燕双飞 提交于 2019-11-27 18:35:40
Are there any ways to automatically trim an MP3 uploaded to a website to 30 seconds (or some other length) in PHP? If not, is there any good 3rd party services that could be integrated (transparently to the user) to achieve the same effect? Thanks. You could try the MP3 Class on PHPClasses. It features the following example: require_once './class.mp3.php'; $mp3 = new mp3; $mp3->cut_mp3('input.mp3', 'output.mp3', 0, -1, 'frame', false); In this case, the 'frame' can be substituted with 'second' to base the cut on a time-frame. I put together a script that outputs a 30 second clip of an MP3 file

How can I configure Entity Framework to automatically trim values retrieved for specific columns mapped to char(N) fields?

怎甘沉沦 提交于 2019-11-27 18:33:16
I'm working with a third-party database in which all text values are stored as char(n) . Some of these text values are primary keys, whereas others are just normal human-readable text. For the latter, I want retrieved values to be automatically trimmed. I know I can add Trim to all of my LINQ to Entities queries, but this is messy, unreliable and unmaintainable. I would like to somehow configure Entity Framework to automatically trim values retrieved from specific columns. However, I don't know how to do this. I'm using EF's fluent API. The closest thing I've thought of so far is creating

Cocoa - Trim all leading whitespace from NSString

隐身守侯 提交于 2019-11-27 17:49:37
(have searched, but not been able to find a simple solution to this one either here, or in Cocoa docs) Q. How can I trim all leading whitespace only from an NSString? (i.e. leaving any other whitespace intact.) Unfortunately, for my purposes, NSString's stringByTrimmingCharactersInSet method works on both leading and trailing. Mac OS X 10.4 compatibility needed, manual GC. John Franklin This creates an NSString category to do what you need. With this, you can call NSString *newString = [mystring stringByTrimmingLeadingWhitespace]; to get a copy minus leading whitespace. (Code is untested, may

String strip() for JavaScript? [duplicate]

佐手、 提交于 2019-11-27 17:07:15
This question already has an answer here: Trim string in JavaScript? 25 answers What's a clean and efficient JavaScript implementation to strip leading and trailing spaces from a string? For example: " dog" "dog " " dog " " dog " all get turned into "dog" David Andres Use this: if(typeof(String.prototype.trim) === "undefined") { String.prototype.trim = function() { return String(this).replace(/^\s+|\s+$/g, ''); }; } The trim function will now be available as a first-class function on your strings. For example: " dog".trim() === "dog" //true EDIT : Took J-P's suggestion to combine the regex

Replace all whitespace characters

人盡茶涼 提交于 2019-11-27 17:05:42
I want to replace all occurrences of white space characters (space, tab, newline) in JavaScript. How to do so? I tried: str.replace(/ /gi, "X") You want \s Matches a single white space character, including space, tab, form feed, line feed. Equivalent to [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff] in Firefox and [ \f\n\r\t\v] in IE . str = str.replace(/\s/g, "X"); \s is a meta character that covers all white space. You don't need to make it case-insensitive — white space doesn't have case. str.replace(/\s/g, "X") We can also use this if we want to change all

JavaScript chop/slice/trim off last character in string

假装没事ソ 提交于 2019-11-27 15:26:01
I have a string, 12345.00 , and I would like it to return 12345.0 . I have looked at trim , but it looks like it is only trimming whitespace and slice which I don't see how this would work. Any suggestions? Jon Erickson You can use the substring function: var str = "12345.00"; str = str.substring(0, str.length - 1); // "12345.0" This is the accepted answer, but as per the conversations below, the slice syntax is much clearer: var str = "12345.00"; str = str.slice(0, -1); // "12345.0" You can use slice ! You just have to make sure you know how to use it. Positive #s are relative to the