trim

How to trim request parameters automatically in playframework

半世苍凉 提交于 2019-12-04 03:25:13
Play will assign the parameters from request to action parameters, like: public static void createArticle(String title, String content) { } But it won't trim them, so we usually to such code in the actions: public static void createArticle(String title, String content) { if(title!=null) title = title.trim(); if(content!=null) content = content.trim(); } Is there any way to let play trim them automatically? There are multiple ways to achive this with custom binders. One way of doing would be this: Define acustom binder somewhere that trims the string Annotate every parameter you want to trim

Trim leading/trailing whitespace from textarea using jQuery?

此生再无相见时 提交于 2019-12-04 03:13:23
问题 Following code is an example of text placed into a textarea from a database. <textarea id="inputPane" cols="80" rows="40" class="pane"> <p> some text here... </p> <p> more text here... </p> </textarea> using jQuery's .trim what is the actual jquery code to remove all leading and trailing whitespace and have the textarea display very similar to below? <textarea id="inputPane" cols="80" rows="40" class="pane"> <p>some text here...</p> <p>more text here...</p> </textarea> I've worked on this for

Javascript Split Space Delimited String and Trim Extra Commas and Spaces

纵然是瞬间 提交于 2019-12-04 02:01:11
I need to split a keyword string and turn it into a comma delimited string. However, I need to get rid of extra spaces and any commas that the user has already input. var keywordString = "ford tempo, with,,, sunroof"; Output to this string: ford,tempo,with,sunroof, I need the trailing comma and no spaces in the final output. Not sure if I should go Regex or a string splitting function. Anyone do something like this already? I need to use javascript (or JQ). EDIT (working solution): var keywordString = ", ,, ford, tempo, with,,, sunroof,, ,"; //remove all commas; remove preceeding and trailing

How to avoid rounding off in NSNumberFormatter

丶灬走出姿态 提交于 2019-12-04 01:57:48
I am trying to have a number string with maximum 2 decimals precision, while rest decimals just trimmed off instead of rounding them up. For example: I have: 123456.9964 I want: 123456.99 -> Just want to trim rest of the decimal places What I have tried is: NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; [numberFormatter setMaximumFractionDigits:2]; NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat: 123456.9964]]; NSLog(@"%@", numberAsString); There is nothing to set

assign “it” in each iteration (groovy)

可紊 提交于 2019-12-04 01:33:13
Hey, i try to trim each string item of an list in groovy list.each() { it = it.trim(); } But this only works within the closure, in the list the strings are still " foo", "bar " and " groovy ". How can i achieve that? list = list.collect { it.trim() } You could also use the spread operator: def list = [" foo", "bar ", " groovy "] list = list*.trim() assert "foo" == list[0] assert "bar" == list[1] assert "groovy" == list[2] According to the Groovy Quick Start , using collect will collect the values returned from the closure. Here's a little example using the Groovy Shell: groovy:000> ["a ", " b

MySQL truncate text with ellipsis

…衆ロ難τιáo~ 提交于 2019-12-04 00:04:15
问题 Suppose I have a MySQL table of one column: "Message". It is of type TEXT. I now want to query all rows, but the text can be large (not extremely large but large) and I only want to get a summary of them. For example the result can be populated into a list. Is there a way to trim the text to a specific length (say, 10 characters), and add ellipsis if the text is trimmed? For example: Message ----------- 12345678901234 1234567890 12345 12345678901 Query result: 1234567... 1234567890 12345

iPhone trim audio recording

萝らか妹 提交于 2019-12-03 20:48:32
I have a voice memo component in my app, and I want to allow the user to trim the audio, similar to QuickTime X on Mac OS Ten point Six handles it, or like the Voice Memos app on the iPhone. Here's an example of both: Any help is appreciated. I am not a UI programmer by any means. This was a test I wrote to see how to write custom controls. This code may or may not work. I have not touched it in some time. header @interface SUIMaxSlider : UIControl { @private float_t minimumValue; float_t maximumValue; float_t value; CGPoint trackPoint; } @property (nonatomic, assign) float_t minimumValue,

How do I remove trailing whitespace from a QString?

£可爱£侵袭症+ 提交于 2019-12-03 19:42:39
问题 I want to remove all the trailing whitespace characters in a QString . I am looking to do what the Python function str.rstrip() with a QString . I did some Googling, and found this: http://www.qtforum.org/article/20798/how-to-strip-trailing-whitespace-from-qstring.html So what I have right now is something like this: while(str.endsWith( ' ' )) str.chop(1); while(str.endsWith( '\n' )) str.chop(1); Is there a simpler way to do this? I want to keep all the whitespace at the beginning. 回答1:

How to trim a string to N chars in Javascript?

对着背影说爱祢 提交于 2019-12-03 18:20:36
问题 How can I, using Javascript, make a function that will trim string passed as argument, to a specified length, also passed as argument. For example: var string = "this is a string"; var length = 6; var trimmedString = trimFunction(length, string); // trimmedString should be: // "this is" Anyone got ideas? I've heard something about using substring, but didn't quite understand. 回答1: Why not just use substring... string.substring(0, 7); The first argument (0) is the starting point. The second

TSQL 2008 Using LTrim(RTrim and still have spaces in the data

末鹿安然 提交于 2019-12-03 18:03:46
问题 I have data I cleaning up in an old data table prior to moving it to a new one. One of the fields has spaces in the column, right & left. I wrote the following code to address this and still have leading spaces?? The bulk of the data is clean when using this code but for some reason there are spaces prior to RT addresses... Has anyone else had this type of issue? ,CASE WHEN PropStreetAddr IS NOT NULL THEN (CONVERT(VARCHAR(28),PropStreetAddr)) WHEN PropStreetAddr is NOT NULL Then (Select LTrim