trim

Trim string to a certain word count

↘锁芯ラ 提交于 2019-12-10 21:28:03
问题 I have a description in my template <p>{{data.description}}</p> I want to trim this description to certain word number, like to first 20 words. I have seen many filters but they trim to a certain characters. This causes the last word to break in most cases. 回答1: You need to split the description string into words, using spaces, then count it: app.filter('words', function () { return function (input, words) { if (isNaN(words)) { return input; } if (words <= 0) { return ''; } if (input) { var

How to remove trailing white spaces and “ ” from the start and end of a string in PHP?

孤街浪徒 提交于 2019-12-10 21:05:13
问题 If $text = '     MEANINGFUL THINGS GO HERE     '; How can I get $cleanText = 'MEANINGFUL THINGS GO HERE'; I know the following will remove all the white spaces $text=trim($text); but how can incorporate actual escaped space into the trim as well? Meaningful Things can contain [shortcodes] , html tags, and also escaped characters. I need these to be preserved. Any help would be appreciated. Thanks! 回答1: $text = '     MEANINGFUL THINGS GO HERE     '; $text = preg_replace( "#(^( |\s)+|( |\s)+$)#

Trim blank newlines from string in Ruby

自古美人都是妖i 提交于 2019-12-10 19:55:13
问题 I have a string of four blank lines which all up makes eight lines in total in the following: str = "aaa\n\n\nbbb\n\nccc\ddd\n" I want to return this all in one line. The output should be like this on a single line: aaabbbcccddd I used various trim functions to get the output but still I am failing. What method do I have to use here? 回答1: The Ruby (and slightly less Perl-ish) way: new_str = str.delete "\n" ...or if you want to do it in-place: str.delete! "\n" 回答2: str.gsub(/\n/,'') 回答3: > str

Is it possible to make trim in a selector?

老子叫甜甜 提交于 2019-12-10 16:48:40
问题 I'd like to count all the inputs in my form which are empty. With empty I mean that its value is empty after trimming its value (if the user insert whitespaces its empty as well). This jquery count them, but it doesn't include the trimming: $(':text').filter('[value=""]').length Has something jquery which can be used to trim in the selector? thanks 回答1: $(':text').filter(function () { return $.trim($(this).val()).length === 0; }); 回答2: While the .filter() method in @Domenic's answer is a good

Trim text- when lot of space keys are entered at end

亡梦爱人 提交于 2019-12-10 16:47:32
问题 I have a edit text field in which reason can be entered. But if a person enters all spaces in the reason how can I detect it. Is there a way when a person enters all spaces or nothing , i have to save the text the text as a simple "hiphen". My main question is how to trim those spaces coming at the end. 回答1: The method trim() in String trims excess spaces on Strings. String str = "Hello "; String str2 = str.trim(); str2 would equal "Hello". As for detecting when a person enters all spaces -

How prevent angular auto trim for fields?

不羁岁月 提交于 2019-12-10 16:09:33
问题 Is there any way prevent angular from auto trim for fields in the whole application? I know that I can prevent it for specified field using ngTrim directive, but it doesn't look good add this directive to all text fields in the application, is there any way do it for all fields in the angular module? Here is code, if you add add spaces in the begin of input they will not appear in label: <div ng-app> <div ng-controller="TodoCtrl"> {{field}} <input type="text" ng-model="field"> </div> </div>

Shorten (Limit) the length of a sentence

瘦欲@ 提交于 2019-12-10 15:04:47
问题 I have column of long names and I would like to cut these to max 40 characters length. Sample data: x <- c("This is the longest sentence in world, so now just make it longer", "No in fact, this is the longest sentence in entire world, world, world, world, the whole world") I would like to shorten the sentece length to about 40 (-/+ 3 nchar) so that I don't shorten the sentence in the middle of an word. (So the length is decised on empty space between words). Also I would like to add 3 dots

How to trim table cell values in MS Word with VBA

本小妞迷上赌 提交于 2019-12-10 14:52:04
问题 I have a table in a Word file. This vba program below will iterate through all the table cells Dim strCellText As String Dim uResp As String Dim Row As Integer Dim Col As Integer Dim itable As Table For Each itable In ThisDocument.Tables uResp = "" For Row = 1 To itable.Rows.Count For Col = 1 To itable.Columns.Count strCellText = itable.Cell(Row, Col).Range.Text uResp = uResp & Trim(strCellText) Next Next MsgBox uResp Next In the line uResp = uResp & Trim(strCellText) VBA appends a newline

Cutting down a length of a PHP string and inserting an ellipses

China☆狼群 提交于 2019-12-10 13:57:35
问题 I want to turn a long string like reallyreallyreallyreallyreallylongfilename into something like reallyreallyre...yreallyreally . Basically, find the middle of the string and replace everything there until the length of the string is < 30 characters including an ellipses to signify there has been parts of the string replaced. This is my code where I have tried this: function cutString($input, $maxLen = 30) { if(strlen($input) < $maxLen) { return $input; } $midPoint = floor(strlen($input) / 2)

Trim only the first and last occurrence of a character in a string (PHP)

℡╲_俬逩灬. 提交于 2019-12-10 11:27:29
问题 This is something I could hack together, but I wondered if anybody had a clean solution to my problem. Something that I throw together wont necessarily be very concise or speedy! I have a string like this ///hello/world/// . I need to strip only the first and last slash, none of the others, so that I get a string like this //hello/world// . PHP's trim isn't quite right right: performing trim($string, '/') will return hello/world . One thing to note is that the string won't necessarily have