DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

12
kicks
published 1 year, 6 months ago, submitted by JamesCurran 1 year, 6 months ago

honestillusion.com — Taking a block of text, and word-wrap it at a specific line length.

Add a comment 4 comments | category: | Views: 2 | Get KickIt image code
tags: , , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
This is a good starting point; however, the code has been mangled by a smiley translator (an "idea" bulb has been inserted for some text). I personally would use regex to do this. You can finely tune the splitting logic. Here are some of the regex strings you can use to split:
// point at which we want to place our breaks
int length = 5;
// an absolute maximum line length; forces hard break at this point
int maxLength = 8;

// Absolute hard break every {0} chars
string hardBreakSpacesIncluded = string.Format("(.{{0,{0}}})",length);
// Hard break after {0} chars excluding whitespace
string hardBreakWithTrailingWhitespace = string.Format("(.{{0,{0}}}\\s*)", length);
// Hard break after {0} chars discarding whitespace past {0} characters
string hardBreakWithoutTrailingWhitespace = string.Format("(.{{0,{0}}})\\s*", length);
// Soft break after {0} chars including trailing whitespace"
string softBreakInclusive = string.Format("(.{{0,{0}}}\\S*\\s*)",length);
// Soft break after {0} chars excluding trailing whitespace
string softBreakExclusive = string.Format("(.{{0,{0}}}\\S*)\\s*", length);
// Soft break after {0} chars and a hard max of {1} chars including trailing whitespace
string softBreakWithSoftMax = string.Format("(.{{0,{0}}}\\S{{0,{1}}}\\s*)", length, maxLength - length);
// Soft break after {0} chars and a hard max of {1} chars excluding trailing whitespace
string softBreakWithHardMax = string.Format("(.{{0,{0}}}\\S{{0,{1}}})\\s*", length, maxLength - length);
posted by yesthatmcgurk yesthatmcgurk 1 year, 6 months ago
Sorry, in comments replace {0} with length and {1} with maxLength, and use Regex.Split(stringToSplit,regexString) to split into an array of strings wrapped at the designated lengths.
posted by yesthatmcgurk yesthatmcgurk 1 year, 6 months ago
Gotta chime in with my version, which simply inserts breaks into a stringbuilder:

http://jasonf-blog.blogspot.com/2005/07/word-wrap-version-2.html
posted by jfollas jfollas 1 year, 5 months ago
Jason: In mine I was trying for the best efficiency. Mine is basically O(n) - Once the StringBuilder is created, each character is copied only once. Every time you call Insert in yours, every character after the insertion point has to be moved down, making it O(n*n) (Of course, the Replace()s at the top of mine kinda screws up the purity of mine, but I'm workin on that.....)
posted by JamesCurran 1 year, 5 months ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge