Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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.

732 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