Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

776 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