chop

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

MySQL/SQL retrieve first 40 characters of a text field?

岁酱吖の 提交于 2019-11-27 07:57:51
How can I retrieve a text field from mysql db table, but not the entire text, just the few 40 or so characters. Can this be done in sql or do I need to do it using php? basically what I am trying to do is show the first x characters and then let the user click on that to view the full content. jensgram SELECT LEFT(field, 40) AS excerpt FROM table(s) WHERE ... See the LEFT() function. As a rule of thumb , you should never do in PHP what MySQL can do for you. Think of it this way: You don't want to transmit anything more than strictly necessary from the DB to the requesting applications. EDIT If

JavaScript chop/slice/trim off last character in string

我是研究僧i 提交于 2019-11-26 18:31:13
问题 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? 回答1: You can use the substring function: let str = "12345.00"; str = str.substring(0, str.length - 1); console.log(str); This is the accepted answer, but as per the conversations below, the slice syntax is much clearer: let str = "12345.00"; str = str.slice(0, -1); console.log(str); 回答2:

MySQL/SQL retrieve first 40 characters of a text field?

社会主义新天地 提交于 2019-11-26 13:56:18
问题 How can I retrieve a text field from mysql db table, but not the entire text, just the few 40 or so characters. Can this be done in sql or do I need to do it using php? basically what I am trying to do is show the first x characters and then let the user click on that to view the full content. 回答1: SELECT LEFT(field, 40) AS excerpt FROM table(s) WHERE ... See the LEFT() function. As a rule of thumb , you should never do in PHP what MySQL can do for you. Think of it this way: You don't want to

JavaScript chop/slice/trim off last character in string

我们两清 提交于 2019-11-26 03:24:59
问题 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? 回答1: You can use the substring function: let str = "12345.00"; str = str.substring(0, str.length - 1); console.log(str); This is the accepted answer, but as per the conversations below, the slice syntax is much clearer: let str = "12345.00"; str = str.slice(0, -1); console.log(str); 回答2:

JavaScript chop/slice/trim off last character in string

佐手、 提交于 2019-11-26 02:22:54
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