truncate

Truncate string on whole words in .NET C#

时光总嘲笑我的痴心妄想 提交于 2019-11-27 06:39:41
I am trying to truncate some long text in C#, but I don't want my string to be cut off part way through a word. Does anyone have a function that I can use to truncate my string at the end of a word? E.g: "This was a long string..." Not: "This was a long st..." Dave Try the following. It is pretty rudimentary. Just finds the first space starting at the desired length. public static string TruncateAtWord(this string value, int length) { if (value == null || value.Length < length || value.IndexOf(" ", length) == -1) return value; return value.Substring(0, value.IndexOf(" ", length)); } TimS

C# DataGridView: Long Text Truncated with “…” on the Left Side When the Column is Right-Aligned

梦想与她 提交于 2019-11-27 06:19:40
问题 I have a question about the cell truncation (replaced with "..."): How to display the replacement "..." on the left side of a cell when the column is right-aligned? I'm using non-equal-width font, so I cannot just count the characters to do some string manipulation as a workaround, I need a solution. I believe there should be. To illustrate my question, I'm simulating my DataGridView here Left Context (Right aligned column) | Center Word | Right Context (Left aligned column) left context not

What is a unix command for deleting the first N characters of a line?

不羁的心 提交于 2019-11-27 05:56:31
For example, I might want to: tail -f logfile | grep org.springframework | <command to remove first N characters> I was thinking that tr might have the ability to do this but I'm not sure. Use cut . Eg. to strip the first 4 characters of each line (i.e. start on the 5th char): tail -f logfile | grep org.springframework | cut -c 5- sed 's/^.\{5\}//' logfile and you replace 5 by the number you want...it should do the trick... EDIT if for each line sed 's/^.\{5\}//g' logfile Ankur You can use cut : cut -c N- file.txt > new_file.txt -c: characters file.txt: input file new_file.txt: output file N-:

I got error “The DELETE statement conflicted with the REFERENCE constraint”

无人久伴 提交于 2019-11-27 05:23:32
I tried to truncate a table with foreign keys and got the message: " Cannot truncate table because it is being referenced by a FOREIGN KEY constraint ". I read a lot of literature about the problem and thought that I found the solution by using delete DELETE FROM table_name DBCC CHECKIDENT (table_name, RESEED, 0) But I still got an error message: " The DELETE statement conflicted with the REFERENCE constraint ". When I try to delete with Microsoft Management Studio and execute the previous query DELETE FROM table_name DBCC CHECKIDENT (table_name, RESEED, 0) it doesn't give an error and works

Truncating a file while it's being used (Linux)

穿精又带淫゛_ 提交于 2019-11-27 04:21:49
问题 I have a process that's writing a lot of data to stdout, which I'm redirecting to a log file. I'd like to limit the size of the file by occasionally copying the current file to a new name and truncating it. My usual techniques of truncating a file, like cp /dev/null file don't work, presumably because the process is using it. Is there some way I can truncate the file? Or delete it and somehow associate the process' stdout with a new file? FWIW, it's a third party product that I can't modify

Truncate a decimal value in C++

…衆ロ難τιáo~ 提交于 2019-11-27 03:28:20
问题 What's the easiest way to truncate a C++ float variable that has a value of 0.6000002 to a value of 0.6000 and store it back in the variable? 回答1: First it is important to know that floating point numbers are approximated. See the link provided by @Greg Hewgill to understand why this problem is not fully solvable. But here are a couple of solutions to the problem that will probably meet your need: Probably the better method but less efficient: char sz[64]; double lf = 0.600000002; sprintf(sz,

Truncate a string straight JavaScript

╄→гoц情女王★ 提交于 2019-11-27 03:04:33
I'd like to truncate a dynamically loaded string using straight JavaScript. It's a url, so there are no spaces, and I obviously don't care about word boundaries, just characters. Here's what I got: var pathname = document.referrer; //wont work if accessing file:// paths document.getElementById("foo").innerHTML = "<a href='" + pathname +"'>" + pathname +"</a>" Use the substring method: var length = 3; var myString = "ABCDEFG"; var myTruncatedString = myString.substring(0,length); // The value of myTruncatedString is "ABC" So in your case: var length = 3; // set to the number of characters you

How to check if UILabel is truncated?

╄→гoц情女王★ 提交于 2019-11-27 02:46:57
I have a UILabel that can be varying lengths depending on whether or not my app is running in portrait or landscape mode on an iPhone or iPad. When the text is too long to show on one line and it truncates I want the user to be able to press it and get a popup of the full text. How can I check to see if the UILabel is truncating the text? Is it even possible? Right now I'm just checking for different lengths based on what mode I'm in but it does not work super well. progrmr You can calculate the width of the string and see if the width is greater than label.bounds.size.width NSString UIKit

Printing fieldsets in firefox

半城伤御伤魂 提交于 2019-11-27 02:44:06
问题 I've been adding some new css to an existing project (using media="print") in the page header. It's going smooth and (for once!) IE is giving nice, expected results, but Firefox does not... The problem is that I have a fieldset which contains a lot of fields, and Firefox completely refuses (even in the latest version) to allow a page break inside the fieldset. This means anything that doesn't fit on one page is lost... I've found the bug acknowledged on the mozilla website which has been open

Truncating Text in PHP? [closed]

和自甴很熟 提交于 2019-11-27 01:52:57
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to truncate some text in PHP and have stumbled across this method (http://theodin.co.uk/blog/development/truncate-text-in-php-the-easy-way.html), which judging by the comments seems like a great easy