truncate

html truncator in java

心已入冬 提交于 2019-12-01 18:25:36
Is there any utility (or sample source code) that truncates HTML (for preview) in Java? I want to do the truncation on the server and not on the client. I'm using HTMLUnit to parse HTML. UPDATE: I want to be able to preview the HTML, so the truncator would maintain the HTML structure while stripping out the elements after the desired output length. I think you're going to need to write your own XML parser to accomplish this. Pull out the body node, add nodes until binary length < some fixed size, and then rebuild the document. If HTMLUnit doesn't create semantic XHTML, I'd recommend tagsoup .

How to limit text string in Eval

倖福魔咒の 提交于 2019-12-01 17:00:00
I have a hyperlink with the navigate property set like this: NavigateUrl='<%# Eval("My Text") %>' How can I limit the string to 140 characters ? I have tried this Eval("My Text").ToString().Substring(0,140) but if the string length is less than 140 characters it throws an exception. And yet an other possibility: Eval("My Text").ToString().PadRight(140).Substring(0,140).TrimEnd() Edit: I do like LINQ, too: Eval("My Text").ToString().Take(140).Aggregate("", (x,y) => x + y) Use It (: < % # Eval("MyText").ToString().Length <= 30 ? Eval("MyText") : Eval("MyText").ToString().Substring(0, 30)+"..." %

Merging two Regular Expressions to Truncate Words in Strings

混江龙づ霸主 提交于 2019-12-01 16:59:44
问题 I'm trying to come up with the following function that truncates string to whole words (if possible, otherwise it should truncate to chars): function Text_Truncate($string, $limit, $more = '...') { $string = trim(html_entity_decode($string, ENT_QUOTES, 'UTF-8')); if (strlen(utf8_decode($string)) > $limit) { $string = preg_replace('~^(.{1,' . intval($limit) . '})(?:\s.*|$)~su', '$1', $string); if (strlen(utf8_decode($string)) > $limit) { $string = preg_replace('~^(.{' . intval($limit) . '}).*

Fast float to int conversion (truncate)

老子叫甜甜 提交于 2019-12-01 15:48:44
I'm looking for a way to truncate a float into an int in a fast and portable (IEEE 754) way. The reason is because in this function 50% of the time is spent in the cast: float fm_sinf(float x) { const float a = 0.00735246819687011731341356165096815f; const float b = -0.16528911397014738207016302002888890f; const float c = 0.99969198629596757779830113868360584f; float r, x2; int k; /* bring x in range */ k = (int) (F_1_PI * x + copysignf(0.5f, x)); /* <-- 50% of time is spent in cast */ x -= k * F_PI; /* if x is in an odd pi count we must flip */ r = 1 - 2 * (k & 1); /* trick for r = (k % 2) ==

How to limit text string in Eval

不羁的心 提交于 2019-12-01 15:22:14
问题 I have a hyperlink with the navigate property set like this: NavigateUrl='<%# Eval("My Text") %>' How can I limit the string to 140 characters ? I have tried this Eval("My Text").ToString().Substring(0,140) but if the string length is less than 140 characters it throws an exception. 回答1: And yet an other possibility: Eval("My Text").ToString().PadRight(140).Substring(0,140).TrimEnd() Edit: I do like LINQ, too: Eval("My Text").ToString().Take(140).Aggregate("", (x,y) => x + y) 回答2: Use It (: <

Read more div with images expand/collapse Toggle excerpt/content

孤街浪徒 提交于 2019-12-01 13:21:54
Okay, I've been spending all day trying to figure out the right approach for this, but have come out short, so maybe someone here can point me in the right direction. Problem: I have a div with class "article-content". There will be around 2-10 of these on the page. Each of them will contain output from a wysiwyg. i.e. texts wrapped in p-tags, some strong tags, em tags and even img tags. I need to create a preview/excerpt version of these that wont show the images and will append a [...] to the end of x characters + a "read more" link. When this is clicked the full article will be shown

SQL Truncate, Delete, Drop advise

非 Y 不嫁゛ 提交于 2019-12-01 10:23:35
问题 I have a table in a SQL db that I want to remove the data from? I want to keep the columns though. e.g. my table has 3 columns, Name, Age, Date. I don't want to remove these, i just want to remove the data. Should I should Truncate, Delete or Drop? 回答1: Don't drop - it will delete the data and the definition. If you delete - the data is gone and auto-increment values go on from the last value. If you truncate - then it is like you just did create the table. No data and all counters resetted

Detecting that log file has been deleted or truncated on POSIX systems?

て烟熏妆下的殇ゞ 提交于 2019-12-01 06:41:29
Suppose a long-running process writes to a log file. Suppose that log file is kept open indefinitely. Suppose that a careless system administrator deletes that log file. Can the program detect that this has happened? Is it safe to assume that fstat() will report a link count of zero for a deleted file? Truncation, it seems to me, is slightly trickier. In part, it depends on whether the file descriptor is running in O_APPEND mode. If the log file is not running with O_APPEND , then the current write position of the program's log descriptor doesn't change, and the truncation removes the leading

URL getting truncated at 255 characters

可紊 提交于 2019-12-01 05:59:34
I have a JavaScript widget which communicates with my Rails app by creating tags in the DOM. Every once in a while, I see a malformed request in my server logs, where the URL is truncated at 255 characters: http://myapplication.example/mycontroller/1/myaction?hostname=www.mycustomer.example&request[param_a]=3&request[param_b]=1&request[param_c]=0&request[param_d]=0&request[param_e]=3&request[param_f]=1&request[param_g]=4&request[param_h]=0&request[param_i]=5&request From Google and Stackoverflow ( What is the maximum length of a URL in different browsers? ), it looks like 255 characters is not

postgres truncate is slow

安稳与你 提交于 2019-12-01 03:22:54
In postgres 9.2 (CentOS), TRUNCATE TABLE command occasionally took a really long time to run. One time, it took more than 1.5 hours to truncate a table with 100K records, even longer in other cases. This problem also happened when I used pgAdmin to truncate table. What is the possible cause? and how to improve the truncation performance? There is 16GB of memory on the server and shared_buffers = 1536MB Craig Ringer TRUNCATE has to flush shared_buffers for the table being truncated, and it has to unlink the old file, which can be slow on file systems with slow deletion like ext3 . 1.5 hours is