Ensures that a given array can hold up to minCapacity elements.

image_pdfimage_print

/*
Copyright 1999 CERN – European Organization for Nuclear Research.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
is hereby granted without fee, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation.
CERN makes no representations about the suitability of this software for any purpose.
It is provided “as is” without expressed or implied warranty.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiscoveryLogic.Common.Numeric
{
public class Arrays : System.Object
{
///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static sbyte[] ensureCapacity(sbyte[] array, int minCapacity)
{
int oldCapacity = array.Length;
sbyte[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new sbyte[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static short[] ensureCapacity(short[] array, int minCapacity)
{
int oldCapacity = array.Length;
short[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new short[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static bool[] ensureCapacity(bool[] array, int minCapacity)
{
int oldCapacity = array.Length;
bool[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new bool[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static char[] ensureCapacity(char[] array, int minCapacity)
{
int oldCapacity = array.Length;
char[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new char[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static double[] ensureCapacity(double[] array, int minCapacity)
{
int oldCapacity = array.Length;
double[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new double[newCapacity]; //for (int i = oldCapacity; --i >= 0; ) newArray[i] = array[i];
Array.Copy(array, 0, newArray, 0, oldCapacity);
}
else
{
newArray = array;
}
return newArray;
}

///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static float[] ensureCapacity(float[] array, int minCapacity)
{
int oldCapacity = array.Length;
float[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new float[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static int[] ensureCapacity(int[] array, int minCapacity)
{
int oldCapacity = array.Length;
int[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new int[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static long[] ensureCapacity(long[] array, int minCapacity)
{
int oldCapacity = array.Length;
long[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new long[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } ///

Ensures that a given array can hold up to minCapacity elements.
///
/// Returns the identical array if it can hold at least the number of elements specified.
/// Otherwise, returns a new array with increased capacity containing the same elements, ensuring
/// that it can hold at least the number of elements specified by
/// the minimum capacity argument.
///
///

/// the desired minimum capacity.
/// public static System.Object[] ensureCapacity(System.Object[] array, int minCapacity)
{
int oldCapacity = array.Length;
System.Object[] newArray;
if (minCapacity > oldCapacity)
{
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity) { newCapacity = minCapacity; } newArray = new System.Object[newCapacity]; Array.Copy(array, 0, newArray, 0, oldCapacity); } else { newArray = array; } return newArray; } } } [/csharp]

Get delimited chars from a string.

image_pdfimage_print
   
 

/*
 * Author: Kishore Reddy
 * Url: http://commonlibrarynet.codeplex.com/
 * Title: CommonLibrary.NET
 * Copyright: ? 2009 Kishore Reddy
 * License: LGPL License
 * LicenseUrl: http://commonlibrarynet.codeplex.com/license
 * Description: A C# based .NET 3.5 Open-Source collection of reusable components.
 * Usage: Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Text;



namespace GenericCode
{
   
    public class StringHelpers
    {
        /// <summary>
        /// Get delimited chars from a string.
        /// </summary>
        /// <param name="rawText">search-classes-workshops-4-1-1-6</param>
        /// <param name="excludeText">search-classes-workshops</param>
        /// <param name="delimiter">-</param>
        /// <returns></returns>
        public static string[] GetDelimitedChars(string rawText, string excludeText, char delimiter)
        {
            int indexOfDelimitedData = rawText.IndexOf(excludeText);
            string delimitedData = rawText.Substring(indexOfDelimitedData + excludeText.Length);
            string[] separatedChars = delimitedData.Split(delimiter);
            return separatedChars;
        }
   }
}

   
     


Remove Trailing Path Delimeter

image_pdfimage_print
   
 
//CruiseControl is open source software and is developed and maintained by a group of dedicated volunteers. 
//CruiseControl is distributed under a BSD-style license.
//http://cruisecontrol.sourceforge.net/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Util
{
    /// <summary>
    /// Class with handy stirng routines
    /// </summary>
    public class StringUtil
    {

        public static string RemoveTrailingPathDelimeter(string directory)
        {
            return string.IsNullOrEmpty(directory) ? string.Empty : directory.TrimEnd(new char[] { Path.DirectorySeparatorChar });
        }
   }
}

   
     


returns the elements of the array as a string, delimited with the default delimitor

image_pdfimage_print
   
 
//CruiseControl is open source software and is developed and maintained by a group of dedicated volunteers. 
//CruiseControl is distributed under a BSD-style license.
//http://cruisecontrol.sourceforge.net/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Util
{
    /// <summary>
    /// Class with handy stirng routines
    /// </summary>
    public class StringUtil
    {

        /// <summary>
        /// returns the elements of the array as a string, delimited with the default delimitor
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public static string GetArrayContents(Array x)
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder();

            string DEFAULT_DELIMITER = ",";
            foreach (object o in x)
            {
                result.AppendFormat("{0}{1} ", o.ToString(), DEFAULT_DELIMITER);
            }

            if (result.Length > 0)
            {
                result.Length -= 2;
            }

            return result.ToString();

        }
    }
}

   
     


New Line Separated String To Array

image_pdfimage_print
   
 
//CruiseControl is open source software and is developed and maintained by a group of dedicated volunteers. 
//CruiseControl is distributed under a BSD-style license.
//http://cruisecontrol.sourceforge.net/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Util
{
    /// <summary>
    /// Class with handy stirng routines
    /// </summary>
    public class StringUtil
    {

        public static string[] NewLineSeparatedStringToArray(string input)
        {
            if (string.IsNullOrEmpty(input))
                return new string[0];

            List<string> targets = new List<string>();
            using (StringReader reader = new StringReader(input))
            {
                while (reader.Peek() >= 0)
                {
                    targets.Add(reader.ReadLine());
                }
            }

            return targets.ToArray();
        }
    }
}

   
     


Array To New Line Separated String

image_pdfimage_print
   
 
//CruiseControl is open source software and is developed and maintained by a group of dedicated volunteers. 
//CruiseControl is distributed under a BSD-style license.
//http://cruisecontrol.sourceforge.net/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Util
{
    /// <summary>
    /// Class with handy stirng routines
    /// </summary>
    public class StringUtil
    {

        public static string ArrayToNewLineSeparatedString(string[] input)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string file in input)
            {
                if (sb.Length > 0)
                    sb.Append(Environment.NewLine);
                sb.Append(file);
            }

            return sb.ToString();
        }
   }
}

   
     


Splits the string into an array, using the separator.

image_pdfimage_print
   
 
         
//
// (C) Copyright 2009 Irantha Suwandarathna (irantha@gmail.com)
// All rights reserved.
//

/* Copyright (c) 2001-2008, The HSQL Development Group
 * All rights reserved.
 *
 * Redistribution and use _in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions _in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer _in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the HSQL Development Group nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


using System;
using System.Text;
using System.Collections.Generic;

namespace EffiProz.Core.Lib
{

    /** Provides a collection of convenience methods for processing and
     * creating objects with <code>String</code> value components.
     *
     * @author fredt@users
     * @author boucherb@users
     * @version 1.7.2
     * @since 1.7.0
     */
    public class StringUtil
    {
        /**
         * Splits the string into an array, using the separator. If separator is
         * not found _in the string, the whole string is returned _in the array.
         *
         * @param s the string
         * @param separator the separator
         * @return array of strings
         */
        public static String[] split(string s, string separator)
        {

            List<string> list = new List<string>();
            int currindex = 0;

            for (bool more = true; more; )
            {
                int nextindex = s.IndexOf(separator, currindex);

                if (nextindex == -1)
                {
                    nextindex = s.Length;
                    more = false;
                }

                list.Add(s.Substring(currindex, nextindex - (currindex)));

                currindex = nextindex + separator.Length;
            }

            return (String[])list.ToArray();
        }
   }
}