Convert ListView to Line separated String Array and vice versa

Glanz Gurke

I am trying to take all items in my ListView and write each one into a new line inside a string Array (or something similar). This is so i can pass these values to a string property inside an object that is then saved to a SQL Database (Varchar(max)).

What i have tried sofar

public string ConvertToString(ListView l)
        {
            ArrayList list = new ArrayList();

            foreach (string item in l.Items)
            {
                list.Add(item);
            }

            return list.ToString();
        }

but im obviously missing the newline split which i am struggling with. The current code only saves "System.Collections.ArrayList" into the database.

I also did alot of googling and keep coming across "string[]" but thats no good as i have to predefine the length, which i dont know as it keeps changing when items get added to the ListView.

I also need a reverse method when reading the values from the database to put each line back into the ListView.

Any help is much appreciated.

Badiboy

StringBuilder perfectly saves the CR/LF chars.

  public string ConvertToString(ListView l)
  {
     StringBuilder list = new StringBuilder();

     foreach (string item in l.Items)
        list.AppendLine(item);

     return list.ToString();
  }

Reverse is similar:

  public voidConvertToString(ListView l, string dbString)
  {
     string [] sep = {"\r\n"};
     foreach (string item in dbString.Split(sep, StringSplitOptions.None))
        l.Items.Add(item);
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert a netty ByteBuf to a String and vice versa

how to convert joda datetime to String and vice versa

How to convert byte array to string and vice versa?

Python convert set to string and vice versa

Convert a byte array to integer in Java and vice versa

Convert an IP string to a number and vice versa

Convert file to byte array and vice versa

How many ways to convert bitmap to string and vice-versa?

How to convert a float into a byte array and vice versa?

Java: Can I convert List of Object to List of String[] and vice versa?

byte to string and vice versa

convert string to json in golang and vice versa?

How do you convert a byte array to a hexadecimal string, and vice versa?

How to convert String[] to String and vice versa in Android

Convert string time to unix time and vice versa

Cannot convert String to byte array and vice versa in Java

Convert ObjectId to String and vice versa inside MongoDB aggregate map

How to convert a string to hex and vice versa in c?

Convert List<int> to string and vice versa?

Converting String to Byte Array and vice versa

Convert a Guid string into BigInteger and vice versa

Convert dataset to xml string with nested repeated xml vice versa

How to convert WCHAR* to string in C++ and vice versa?

Convert struct array to cell of structs and vice versa

ByteBuffer - convert long to char array and vice versa

How to convert string variable to int and vice versa in CLASSIC ASP

Convert the string containing array and dict into the list and vice versa in c#

How to convert string into numpy array for tensorflow and vice versa

How to convert numpy array to string and vice versa