Most of the technical posts I make on this blog, are issues that I struggle with for a day or two, and was unable to find a good solution for on the internet. Once I find the solution, I try to post it here, to try and make things easier on everyone else out there. I made a similar post to usenet microsoft.public.dotnet.faqs group last April, about doing word wrap in .net. This weekend, someone sent some feedback from my blog asking if that post was mine, and thanking me for the information. I really appreciated the comment, since it is hard to tell if people out there need and use the information I post.
In any case, I decided to repost the word wrap function to my blog, in hopes that more people can get some use out of it.
public
static string[] Wrap(string text, int maxLength)
{
text = text.Replace("\n", " ");
text = text.Replace("\r", " ");
text = text.Replace(".", ". ");
text = text.Replace(">", "> ");
text = text.Replace("\t", " ");
text = text.Replace(",", ", ");
text = text.Replace(";", "; ");
text = text.Replace("
", " ");
text = text.Replace(" ", " ");
string[] Words = text.Split(' ');
int currentLineLength = 0;
ArrayList Lines = new ArrayList(text.Length / maxLength);
string currentLine = "";
bool InTag = false;
foreach (string currentWord in Words)
{
//ignore html
if (currentWord.Length > 0)
{
if (currentWord.Substring(0,1) == "<")
InTag = true;
if (InTag)
{
//handle filenames inside html tags
if (currentLine.EndsWith("."))
{
currentLine += currentWord;
}
else
currentLine += " " + currentWord;
if (currentWord.IndexOf(">") > -1)
InTag = false;
}
else
{
if (currentLineLength + currentWord.Length + 1 < maxLength)
{
currentLine += " " + currentWord;
currentLineLength += (currentWord.Length + 1);
}
else
{
Lines.Add(currentLine);
currentLine = currentWord;
currentLineLength = currentWord.Length;
}
}
}
}
if (currentLine != "")
Lines.Add(currentLine);
string[] textLinesStr = new string[Lines.Count];
Lines.CopyTo(textLinesStr, 0);
return textLinesStr;
}
I saw a post over at Hand Coding comparing his Nikon 5700 to a PT Cruiser. Like many hybrid gadgets, the pro-sumer point and shoots end up being a bad compromise. Cameras like the 5700 have none of the convinience of a point and shoot. They are big and bulky. But they have almost none of the advantages of a Digital SLR either. They do have bigger glass, and a bigger sensor, which gives a much better quality picture than the compact point and shoot, but almost everywhere else, they suffer. No interchangable lenses (but no dust on the upside), shutter lag, limited ISO, and apetures etc. They even cost as much (or more) as some of the cheaper DSLRs like the Nikon D50
With both my previous D70, and my current D200, I use it as my only camera. I do have one of the early generation Canon Digital Elphs (4MP, 3x zoom) but I almost never take it with me. Its a thing you get used to. I carry around a huge bag, with my camera, 4-5 lenses, and a flash. Certainly I can't take this with me everywhere I go, but for the random photographic note taking (buy this book, remember this street) I use my camera phone. The phone works for the most other things as well. Sure the pictures are no where near the quality of the DSLR. But neither is the point and shoot! This is going to become even more true as camera phones improve their quality.
For more casual outings (bars, shopping, whatever) I grab the D200, and pick whatever lens makes the most sense. For bars, I take the Nikkor 50mm 1.4 lens which is insanely fast. A point and shoot will never be able to get pictures like this lens can- they are just too slow. For most other situations I use the Tamron 28-300, just because I never know which focal length I want. Sometimes I toss the 50mm in my pocket just in case things get dark. Its so small I dont even notice it. It isn't as sharp as a lens with less zoom, but its still way better than a point and shoot, and so convinient.