truncate

How to truncate STDIN line length?

风格不统一 提交于 2019-12-19 02:47:28
问题 I've been parsing through some log files and I've found that some of the lines are too long to display on one line so Terminal.app kindly wraps them onto the next line. However, I've been looking for a way to truncate a line after a certain number of characters so that Terminal doesn't wrap, making it much easier to spot patterns. I wrote a small Perl script to do this: #!/usr/bin/perl die("need max length\n") unless $#ARGV == 0; while (<STDIN>) { $_ = substr($_, 0, $ARGV[0]); chomp($_);

Javascript truncate HTML text

拈花ヽ惹草 提交于 2019-12-18 20:17:47
问题 Does JavaScript have a way of truncating HTML text without all the headaches of matching tags etc etc? Thank you. 回答1: There's nothing built-in javascript. There's a jQuery plugin that you might take a look at. 回答2: I had the same problem, and wound up writing the following to deal with it. It truncates HTML to a give length, cleans up any start / end tags that might have gotten snipped off at the end, and then closes any tags left unclosed: function truncateHTML(text, length) { var truncated

Javascript truncate HTML text

隐身守侯 提交于 2019-12-18 20:17:10
问题 Does JavaScript have a way of truncating HTML text without all the headaches of matching tags etc etc? Thank you. 回答1: There's nothing built-in javascript. There's a jQuery plugin that you might take a look at. 回答2: I had the same problem, and wound up writing the following to deal with it. It truncates HTML to a give length, cleans up any start / end tags that might have gotten snipped off at the end, and then closes any tags left unclosed: function truncateHTML(text, length) { var truncated

sqlite3 is chopping/cutting/truncating my text columns

Deadly 提交于 2019-12-18 13:59:08
问题 I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id left join statenames f on f.st = l.st left join statenames t on t.st = l.stto where n.timing > 200601 and count(n.timing)<=15" Which gives me name From State To State ---------- ----------- ---------- Jack Connecticut Louisiana Jeff Danie New Hampshi New Hampsh The names are being truncated down to

Truncate a string without cut in the middle of a word in rails

孤人 提交于 2019-12-18 12:52:46
问题 How can i truncate a text to the closest position with rails 3 whithout cut in the middle of a word? For exemple, I have the string : "Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum." If i cut it, i want to cut like this : "Praesent commodo cursus magna, vel scelerisque nisl ..." And not : "Praesent commodo cursus magna, vel scelerisque nisl conse..." 回答1: If you pass in a separator to the

Truncating unicode so it fits a maximum size when encoded for wire transfer

烈酒焚心 提交于 2019-12-18 12:13:34
问题 Given a Unicode string and these requirements: The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape) The encoded string has a maximum length For example, the iPhone push service requires JSON encoding with a maximum total packet size of 256 bytes. What is the best way to truncate the string so that it re-encodes to valid Unicode and that it displays reasonably correctly? (Human language comprehension is not necessary—the truncated version can look odd e.g.

truncate string from a certain character in R [duplicate]

不羁的心 提交于 2019-12-18 11:46:58
问题 This question already has answers here : How do I specify a dynamic position for the start of substring? (4 answers) Closed last year . I have a list of strings in R which looks like: WDN.TO WDR.N WDS.AX WEC.AX WEC.N WED.TO I want to get all the postfix of the strings starting from the character ".", the result should look like: .TO .N .AX .AX .N .TO Anyone have any ideas? 回答1: Joshua's solution works fine. I'd use sub instead of gsub though. gsub is for substituting multiple occurrences of a

How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded?

守給你的承諾、 提交于 2019-12-18 11:01:12
问题 How do I truncate a java String so that I know it will fit in a given number of bytes storage once it is UTF-8 encoded? 回答1: Here is a simple loop that counts how big the UTF-8 representation is going to be, and truncates when it is exceeded: public static String truncateWhenUTF8(String s, int maxBytes) { int b = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); // ranges from http://en.wikipedia.org/wiki/UTF-8 int skip = 0; int more; if (c <= 0x007f) { more = 1; } else if (c <=

How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded?

懵懂的女人 提交于 2019-12-18 11:01:06
问题 How do I truncate a java String so that I know it will fit in a given number of bytes storage once it is UTF-8 encoded? 回答1: Here is a simple loop that counts how big the UTF-8 representation is going to be, and truncates when it is exceeded: public static String truncateWhenUTF8(String s, int maxBytes) { int b = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); // ranges from http://en.wikipedia.org/wiki/UTF-8 int skip = 0; int more; if (c <= 0x007f) { more = 1; } else if (c <=

SQL Query to truncate table in IBM DB2

孤街浪徒 提交于 2019-12-18 05:55:42
问题 Can any one give me the syntax to truncate a table in IBM DB2. I m running the following command: truncate table tableName immediate; The eror is DB2 SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;truncate ;JOIN , DRIVER=3.50.152 Message: An unexpected token "table" was found following "truncate ". Expected tokens may include: "JOIN ".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.50.152 The syntax matches the one specified in the reference docs of IBM : http://publib.boulder.ibm.com/infocenter