/* * 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; } } }
Author: coder
Remove Trailing Path Delimeter
//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
//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
//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
//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.
// // (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(); } } }
Gets an array of sentences from a string.
#region Copyright (c) 2004, Ryan Whitaker /********************************************************************************* ' ' Copyright (c) 2004 Ryan Whitaker ' ' This software is provided 'as-is', without any express or implied warranty. In no ' event will the authors be held liable for any damages arising from the use of this ' software. ' ' Permission is granted to anyone to use this software for any purpose, including ' commercial applications, and to alter it and redistribute it freely, subject to the ' following restrictions: ' ' 1. The origin of this software must not be misrepresented; you must not claim that ' you wrote the original software. If you use this software in a product, an ' acknowledgment (see the following) in the product documentation is required. ' ' This product uses software written by the developers of NClassifier ' (http://nclassifier.sourceforge.net). NClassifier is a .NET port of the Nick ' Lothian's Java text classification engine, Classifier4J ' (http://classifier4j.sourceforge.net). ' ' 2. Altered source versions must be plainly marked as such, and must not be ' misrepresented as being the original software. ' ' 3. This notice may not be removed or altered from any source distribution. ' '********************************************************************************/ #endregion using System; using System.Collections; using System.Text.RegularExpressions; namespace NClassifier { public class Utilities { /// <summary> /// Gets an array of sentences. /// </summary> /// <param name="input">A string that contains sentences.</param> /// <returns>An array of strings, each element containing a sentence.</returns> public static string[] GetSentences(string input) { if (input == null) return new string[0]; else { // split on a ".", a "!", a "?" followed by a space or EOL // the original Java regex was (.|!|?)+(s|z) string[] result = Regex.Split(input, @"(?:.|!|?)+(?:s+|z)"); // hacky... doing this to pass the unit tests ArrayList list = new ArrayList(); foreach (string s in result) if (s.Length > 0) list.Add(s); return (string[])list.ToArray(typeof(string)); } } } }