Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

System.Text.StringBuilder class


  • Please log in to reply
No replies to this topic

#1 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 August 2010 - 10:02 PM

Here is a very preliminary implementation of the .NET Framework's StringBuilder class, placed in the System.Text namespace for code compatibility with desktop/mobile C# applications.

This sample code uses an ArrayList and is not performance-optimized.

System.Text.StringBuilder.cs
using System;
using System.Collections;
using Microsoft.SPOT;

namespace System.Text
{
    class StringBuilder
    {
        ArrayList m_charArray = new ArrayList();

        public StringBuilder()
        {
        }

        public StringBuilder(string value) : base()
        {
            Append(value);
        }

        public void Append(string value)
        {
            Char[] charArray = value.ToCharArray();
            Append(charArray, 0, charArray.Length);
        }

        public void Append(char[] value, int startIndex, int charCount)
        {
            for (int index = startIndex; index < startIndex + charCount; index++)
                m_charArray.Add(value[index]);
        }

        public int Length
        {
            get
            {
                return m_charArray.Count;
            }
        }

        public override string ToString()
        {
            return new string((char[])m_charArray.ToArray(typeof(char)));
        }
    }
}

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.