trim

trimws bug? leading whitespace not removed

喜你入骨 提交于 2019-11-29 14:33:30
Edit : Thanks to R Yoda , I was finally able to create a reproducible example to the issue I am facing: x = rawToChar(as.raw(c(0xa0, 0x31, 0x31, 0x2e, 0x31, 0x33, 0x32, 0x35, 0x39, 0x32))) trimws(x) => Question: How can I trim x? Old text of the question: Please see attached screenshot. Unfortunately I am not able to create reproducible example as dput is affecting the result... As anyone an idea how to investigate what's going wrong with x? The leading whitespace doesn't seem to be a standard one! charToRaw(x) gives a0 31 31 2e 31 33 32 35 39 32 dput(charToRaw(x)) gives as.raw(c(0xa0, 0x31,

How to trim text using PHP

谁都会走 提交于 2019-11-29 14:30:22
How to trim some word in php? Example like pid="5" OR pid="3" OR I want to remove the last OR I suggest using implode() to stick together SQL expressions like that. First build an array of simple expressions, then implode them with OR: $pids = array('pid = "5"', 'pid = "3"'); $sql_where = implode(' OR ', $pids); Now $sql_where is the string 'pid = "5" OR pid = "3"' . You don't have to worry about leftover ORs, even when there is only one element in $pids . Also, an entirely different solution is to append " false" to your SQL string so it will end in "... OR false" which will make it a valid

MYSQL disable Auto-Trim

最后都变了- 提交于 2019-11-29 14:20:34
If I enter two Strings with only white space. I will Get this error message: ERROR 1062: Duplicate entry ' ' for key 'PRIMARY' How can I Turn off "Auto-Trim" ? I'm Using this Charset: uft8-uft8_bin and This Datatype: Varchar . Hugo Delsing According to the SQL 92 documentation, when two strings are compared they are first made equal in length by padding the shortest string with spaces. Search for 8.2 <comparison predicate> in the document. If the length in characters of X is not equal to the length in characters of Y, then the shorter string is effectively replaced, for the purposes of

How do I remove white-space from the beginning of a string?

瘦欲@ 提交于 2019-11-29 14:04:07
How do I remove white-space from the beginning of a string in Java without removing from the end? If the value is: String temp = " hi " Then how can I delete only the leading white-space so it looks like this: String temp = "hi " The current implementation I have is to loop through, checking the first character and creating a substring until the first non-whitespace value is reached. Thanks! You could use: temp = temp.replaceFirst("^\\s*", "") You could use Commons-lang StringUtils stripStart method. If you pass null it will automatically trim the spaces. StringUtils.stripStart(temp, null);

Trim leading spaces including tabs

血红的双手。 提交于 2019-11-29 10:56:01
I need to read files using vbscript and remove all leading spaces including any tabs. I now LTRIM will remove the leading spaces but how do I remove tabs also. Thanks. This function removes all leading whitespace (spaces, tabs etc) from a string: Function LTrimEx(str) Dim re Set re = New RegExp re.Pattern = "^\s*" re.Multiline = False LTrimEx = re.Replace(str, "") End Function For a both left and right trim (including tabs, carriage return, line feeds, spaces) in a multiline string this will work. Function MultilineTrim (Byval TextData) Dim textRegExp Set textRegExp = new regexp textRegExp

Is there a “bounding box” function (slice with non-zero values) for a ndarray in NumPy?

为君一笑 提交于 2019-11-29 09:13:05
I am dealing with arrays created via numpy.array(), and I need to draw points on a canvas simulating an image. Since there is a lot of zero values around the central part of the array which contains the meaningful data, I would like to "trim" the array, erasing columns that only contain zeros and rows that only contain zeros. So, I would like to know of some native numpy function or even a code snippet to "trim" or find a "bounding box" to slice only the data-containing part of the array. (since it is a conceptual question, I did not put any code, sorry if I should, I'm very fresh to posting

String from byte array doesn't get trimmed in C#?

随声附和 提交于 2019-11-29 09:07:10
I have a byte array similar to this (16 bytes): 71 77 65 72 74 79 00 00 00 00 00 00 00 00 00 00 I use this to convert it to a string and trim the ending spaces: ASCIIEncoding.ASCII.GetString(data).Trim(); I get the string fine, however it still has all the ending spaces. So I get something like "qwerty.........." (where dots are spaces due to StackOverflow). What am I doing wrong? I also tried to use .TrimEnd() and to use an UTF8 encoding, but it doesn't change anything. Thanks in advance :) Walt W You have to do TrimEnd(new char[] { (char)0 }); to fix this. It's not spaces - it's actually

php truncate string if longer than limit and put some omission at the end..similar to ruby

試著忘記壹切 提交于 2019-11-29 08:21:10
I need this functionality in my recent php code many times, So I am lookin for a function to do the work, if there exists any.. If the string if bigger than the limit truncate it and put some omission text like ...(continued) .. Like in ruby we have truncate function on string "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)") I could do it by first checking the length exceeds.. then trim, then concatenation...But I am looking for some function similar.. function substr_with_ellipsis($string, $chars = 100) { preg_match('/^.{0,' . $chars. '}(?:.

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

烈酒焚心 提交于 2019-11-29 07:02:42
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(RTrim(PropStreetAddr)) As PropStreetAddr) ELSE NULL END as 'PROPERTY_STREET_ADDRESS' Sample output

trim in javascript ? what this code is doing?

人盡茶涼 提交于 2019-11-29 05:31:26
I was looking for a trim function in JavaScript which doesn't exist and some code on Googling suggests that use: function trimStr(str) { return str.replace(/^\s+|\s+$/g, ''); } I want to know how str.replace(/^\s+|\s+$/g, '') works. I understand that this is some form of regular expression but dont know what it is doing. /^\s+|\s+$/g searches for whitespace from either the beginning or the end of the string. The expression can be split into two parts, ^\s+ and \s+$ which are separated by | (OR). The first part starts from the beginning of the string ( ^ ) and includes as many whitespace