Solved

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

Posted on 2010-08-30
2
605 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now