Solved

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

Posted on 2010-08-30
2
632 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

688 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