Questions tagged [truncation]

The process of shortening data by discarding a portion of it.

Data truncation occurs when only a portion of data or a data stream (such as a file) is stored.

Data truncation may occur automatically, such as when a long string is written to a smaller buffer, or deliberately, when only a portion of the data is wanted.

352 questions
377
votes
21 answers

Truncate a string to first n characters of a string and add three dots if any characters are removed

How can I get the first n characters of a string in PHP? What's the fastest way to trim a string to a specific number of characters, and append '...' if needed?
Alex
  • 66,732
  • 177
  • 439
  • 641
267
votes
27 answers

Smart way to truncate long strings

Does anyone have a more sophisticated solution/library for truncating strings with JavaScript and putting an ellipsis on the end, than the obvious one: if (string.length > 25) { string = string.substring(0, 24) + "..."; }
naltatis
  • 2,953
  • 2
  • 18
  • 9
76
votes
7 answers

SQL Server silently truncates varchar's in stored procedures

According to this forum discussion, SQL Server (I'm using 2005 but I gather this also applies to 2000 and 2008) silently truncates any varchars you specify as stored procedure parameters to the length of the varchar, even if inserting that string…
Jez
  • 27,951
  • 32
  • 136
  • 233
70
votes
17 answers

Ellipsis in the middle of a text (Mac style)

I need to implement ellipsis ("...") in the middle of a text within a resizable element. Here is what it might look like. So, "Lorem ipsum dolor sit amet. Ut ornare dignissim ligula sed commodo." becomes "Lorem ipsum dolor sit amet ...…
user102465
64
votes
6 answers

How to truncate a file in C?

I'm using C to write some data to a file. I want to erase the previous text written in the file in case it was longer than what I'm writing now. I want to decrease the size of file or truncate until the end. How can I do this?
sofr
  • 5,407
  • 6
  • 28
  • 29
58
votes
10 answers

SQL Server truncation and 8192 limitation

In SQL Server 2005 I am trying to query a varchar(MAX) column which has some rows with text data that exceed the 8192. Yet, In Management Studio I have under Tools --> Options --> Query Results --> Results to Text --> Max numbers of characters…
Ash Machine
  • 9,601
  • 11
  • 45
  • 52
39
votes
11 answers

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'column_name'

I am using Java JDBC with MySQL and I get this error: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'column_name' How do I remedy this error?
thilo
  • 439
  • 1
  • 5
  • 6
31
votes
9 answers

How can I get the full string of PHP’s getTraceAsString()?

I'm using getTraceAsString() to get a stack trace but the string is being truncated for some reason. Example, an exception is thrown and I log the string using: catch (SoapFault $e) { error_log( $e->getTraceAsString() ) } The string thats prints…
User
  • 62,498
  • 72
  • 186
  • 247
29
votes
5 answers

call to undefined function mb_strimwidth

Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string. Now, after some times, I tried to execute that same code and it went out with this error: Fatal…
Yuri
  • 3,082
  • 3
  • 28
  • 47
27
votes
3 answers

Why is T-SQL ISNULL() truncating the string and COALESCE is not?

Given the following: SELECT ISNULL('XY' + NULL, 'ABCDEFGHIJ') -- Outputs ABC (Why?) SELECT COALESCE('XY' + NULL, 'ABCDEFGHIJ') -- Outputs ABCDEFGHIJ Why are these statements returning different results?
natenho
  • 5,231
  • 4
  • 27
  • 52
19
votes
13 answers

How can I mimic text-overflow: ellipsis in Firefox?

I have some dynamic text contained in a div that is set to whatever a user enters in a textbox field. If the text doesn't fit in the div, right now it just gets cut off at the edge and all the text that extends past the border is not visible. I…
Brian Schroth
  • 2,447
  • 1
  • 15
  • 26
18
votes
6 answers

How can I truncate a line of text longer than a given length?

How would you go about removing everything after x number of characters? For example, cut everything after 15 characters and add ... to it. This is an example sentence should turn into This is an exam...
undefinedChar
  • 537
  • 1
  • 5
  • 18
18
votes
8 answers

How do I check if a char is a vowel?

This Java code is giving me trouble: String word = int y = 3; char z; do { z = word.charAt(y); if (z!='a' || z!='e' || z!='i' || z!='o' || z!='u')) { for (int i = 0; i==y; i++) { …
Dinocv
  • 367
  • 2
  • 3
  • 10
17
votes
4 answers

Android TextView Truncation Priority or Compression Resistance

I'm laying out 3 views horizontally on the screen (fixed-size image and 2 single-line text views: leftTextView and rightTextView) and I'm trying to get the rightTextView to hug against the leftTextView, but in the event that the width of both labels…
Stonz2
  • 6,306
  • 4
  • 44
  • 64
16
votes
2 answers

Is there an orthodox way to avoid compiler warning C4309 - "truncation of constant value" with binary file output?

My program does the common task of writing binary data to a file, conforming to a certain non-text file format. Since the data I'm writing is not already in existing chunks but instead is put together byte by byte at runtime, I use…
Sam Kauffman
  • 1,221
  • 11
  • 30
1
2 3
23 24