Solved

How to break up a large text string from a SQL Server nvarchar(max) field

Posted on 2010-08-30
2
620 Views
Last Modified: 2013-12-14
We have a VS 2010 C# form that requires the the end user to give a detailed explanation to a question.  This question is stored in SQL 2008 R2 as nvarchar(max) When generating the text to a text file, the field runs off the page and does not care about margin.  Is there a way to have this field formatted adhere to certain margins when written to the text file? Since the user may or mat not use a cr in the textbox, there could be paragraphs of text.  I would think the best way would be to put some kind of logic in and programatically insert \r\n
0
Comment
Question by:iamtheiam
  • 2
2 Comments
 

Author Comment

by:iamtheiam
ID: 33562992
in case anyone is thinking "why nvarchar(max)?"  We need to be able to store english, spanish and vietnamese answers.  This was the only data type that we could find that would store the answer correctly.
0
 

Accepted Solution

by:
iamtheiam earned 0 total points
ID: 33570497
             string narrative = GetWritingTestResultDetails[0].narrative;
                string nwline = "";
                string[] stokens = narrative.Split(new char[] { ' ' });
                char[] seps = new char[] { ' ' };
                if (narrative.Length <= 85)
                {
                    sw.WriteLine(narrative);
                }
                else
                {
                    stokens = narrative.Split(new char[] { ' ' });
                    seps = new char[] { ' ' };
                    nwline = "";
                    foreach (string ss in narrative.Split(seps))
                    {
                        nwline += ss + " ";
                        if (nwline.Length > 85)
                        {
                            sw.WriteLine(nwline);
                            nwline = "";
                        }
                    }
                    if (nwline.Length < 85)//to capture the last line
                    {
                        sw.WriteLine(nwline);
                        nwline = "";
                    }
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question