本文整理汇总了C#中StringCollection.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# StringCollection.AddRange方法的具体用法?C# StringCollection.AddRange怎么用?C# StringCollection.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringCollection
的用法示例。
在下文中一共展示了StringCollection.AddRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromString
public static StringCollection FromString(string value, char separator)
{
StringCollection col = new StringCollection();
if (value.Length > 0)
{
col.AddRange(value.Split(separator));
}
return col;
}
示例2: Clone
public StringCollection Clone()
{
StringCollection c = new StringCollection();
if (Count > 0)
{
string[] strings = new string[Count];
CopyTo(strings, 0);
c.AddRange(strings);
}
return c;
}
示例3: Insert_Data
/// <summary>
/// Data used for testing with Insert.
/// </summary>
/// Format is:
/// 1. initial Collection
/// 2. internal data
/// 3. data to insert (ElementNotPresent or null)
/// 4. location to insert (0, count / 2, count)
/// <returns>Row of data</returns>
public static IEnumerable<object[]> Insert_Data()
{
foreach (object[] data in StringCollection_Data().Concat(StringCollection_Duplicates_Data()))
{
string[] d = (string[])(data[1]);
foreach (string element in new[] { ElementNotPresent, null })
{
foreach (int location in new[] { 0, d.Length / 2, d.Length }.Distinct())
{
StringCollection initial = new StringCollection();
initial.AddRange(d);
yield return new object[] { initial, d, element, location };
}
}
}
}/// <summary>
示例4: RemoveAt_Data
}/// <summary>
/// Data used for testing with RemoveAt.
/// </summary>
/// Format is:
/// 1. initial Collection
/// 2. internal data
/// 3. location to remove (0, count / 2, count)
/// <returns>Row of data</returns>
public static IEnumerable<object[]> RemoveAt_Data()
{
foreach (object[] data in StringCollection_Data().Concat(StringCollection_Duplicates_Data()))
{
string[] d = (string[])(data[1]);
if (d.Length > 0)
{
foreach (int location in new[] { 0, d.Length / 2, d.Length - 1 }.Distinct())
{
StringCollection initial = new StringCollection();
initial.AddRange(d);
yield return new object[] { initial, d, location };
}
}
}
}
示例5: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringCollection sc;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. RemoveAt() from empty collection");
iCountTestcases++;
if (sc.Count > 0)
sc.Clear();
try
{
sc.RemoveAt(0);
iCountErrors++;
Console.WriteLine("Err_0001_{0}a, no exception");
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}b, unexpected exception: " + e.ToString());
}
Console.WriteLine("2. RemoveAt() on filled collection");
strLoc = "Loc_002oo";
Console.WriteLine(" - at the beginning");
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
}
iCountTestcases++;
sc.RemoveAt(0);
if (sc.Count != values.Length - 1)
{
iCountErrors++;
Console.WriteLine("Err_0002b, Count returned {0} instead of {1}", sc.Count, values.Length - 1);
}
iCountTestcases++;
if (sc.Contains(values[0]))
{
iCountErrors++;
Console.WriteLine("Err_0002c, removed wrong item");
}
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (sc.IndexOf(values[i]) != i-1)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}d, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i-1);
}
}
Console.WriteLine(" - at the end");
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002e, count is {0} instead of {1}", sc.Count, values.Length);
}
iCountTestcases++;
sc.RemoveAt(values.Length-1);
if (sc.Count != values.Length - 1)
{
iCountErrors++;
Console.WriteLine("Err_0002f, Count returned {0} instead of {1}", sc.Count, values.Length - 1);
}
iCountTestcases++;
if (sc.Contains(values[values.Length - 1]))
{
//.........这里部分代码省略.........
示例6: GetSetting
// Retrieve values from the configuration file, or if the setting does not exist in the file,
// retrieve the value from the application's default configuration
private object GetSetting(SettingsProperty setProp)
{
object retVal;
try
{
// Search for the specific settings node we are looking for in the configuration file.
// If it exists, return the InnerText or InnerXML of its first child node, depending on the setting type.
// If the setting is serialized as a string, return the text stored in the config
if (setProp.SerializeAs.ToString() == "String")
{
return XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']").FirstChild.InnerText;
}
// If the setting is stored as XML, deserialize it and return the proper object. This only supports
// StringCollections at the moment - I will likely add other types as I use them in applications.
else
{
string settingType = setProp.PropertyType.ToString();
string xmlData = XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']").FirstChild.InnerXml;
XmlSerializer xs = new XmlSerializer(typeof(string[]));
string[] data = (string[])xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null));
switch (settingType)
{
case "System.Collections.Specialized.StringCollection":
StringCollection sc = new StringCollection();
sc.AddRange(data);
return sc;
default:
return "";
}
}
}
catch (Exception)
{
// Check to see if a default value is defined by the application.
// If so, return that value, using the same rules for settings stored as Strings and XML as above
if ((setProp.DefaultValue != null))
{
if (setProp.SerializeAs.ToString() == "String")
{
retVal = setProp.DefaultValue.ToString();
}
else
{
string settingType = setProp.PropertyType.ToString();
string xmlData = setProp.DefaultValue.ToString();
XmlSerializer xs = new XmlSerializer(typeof(string[]));
string[] data = (string[])xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null));
switch (settingType)
{
case "System.Collections.Specialized.StringCollection":
StringCollection sc = new StringCollection();
sc.AddRange(data);
return sc;
default: return "";
}
}
}
else
{
retVal = "";
}
}
return retVal;
}
示例7: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
StringCollection sc;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
try
{
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. IsSynchronized on empty collection");
iCountTestcases++;
if (sc.IsSynchronized)
{
iCountErrors++;
Console.WriteLine("Err_0001, returned true for empty collection");
}
Console.WriteLine("2. IsSynchronized for filled collection");
strLoc = "Loc_002oo";
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
}
iCountTestcases++;
if (sc.IsSynchronized)
{
iCountErrors++;
Console.WriteLine("Err_0002b, returned true for filled collection");
}
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例8: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
StringCollection sc;
StringEnumerator en;
string curr;
string [] values =
{
"a",
"aa",
"",
" ",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
try
{
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. Enumerator for empty collection");
Console.WriteLine(" - get type");
iCountTestcases++;
en = sc.GetEnumerator();
string type = en.GetType().ToString();
if ( type.IndexOf("StringEnumerator", 0) == 0 )
{
iCountErrors++;
Console.WriteLine("Err_0001a, type is not StringEnumerator");
}
Console.WriteLine(" - MoveNext");
iCountTestcases++;
bool res = en.MoveNext();
if ( res )
{
iCountErrors++;
Console.WriteLine("Err_0001b, MoveNext returned true");
}
Console.WriteLine(" - Current");
iCountTestcases++;
try
{
curr = en.Current;
iCountErrors++;
Console.WriteLine("Err_0001c, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString());
}
Console.WriteLine(" - Add item to the collection");
iCountTestcases++;
int cnt = sc.Count;
sc.Add(values[0]);
if ( sc.Count != 1)
{
iCountErrors++;
Console.WriteLine("Err_0001e, failed to add item");
}
Console.WriteLine(" - MoveNext on modified collection");
try
{
res = en.MoveNext();
iCountErrors++;
Console.WriteLine("Err_0001f, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001g, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("2. Enumerator for filled collection");
strLoc = "Loc_002oo";
iCountTestcases++;
sc.AddRange(values);
Console.WriteLine(" - get type");
iCountTestcases++;
en = sc.GetEnumerator();
type = en.GetType().ToString();
if ( type.IndexOf("StringEnumerator", 0) == 0 )
{
iCountErrors++;
//.........这里部分代码省略.........
示例9: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringCollection sc;
string itm;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. get Item from empty collection");
Console.WriteLine(" (-1)th");
strLoc = "Loc_001oo";
iCountTestcases++;
try
{
itm = sc[-1];
iCountErrors++;
Console.WriteLine("Err_0001a, no exception");
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString());
}
Console.WriteLine(" 0th");
iCountTestcases++;
try
{
itm = sc[0];
iCountErrors++;
Console.WriteLine("Err_0001c, no exception");
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("2. Get Item on collection with simple strings");
strLoc = "Loc_002oo";
sc.Clear();
iCountTestcases++;
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
}
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (String.Compare(sc[i], values[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, returned {1} instead of {2}", i, sc[i], values[i]);
}
}
Console.WriteLine("3. get Item on collection with intl strings");
strLoc = "Loc_003oo";
string [] intlValues = new string [values.Length];
for (int i = 0; i < values.Length; i++)
{
string val = intl.GetString(MAX_LEN, true, true, true);
while (Array.IndexOf(intlValues, val) != -1 )
val = intl.GetString(MAX_LEN, true, true, true);
intlValues[i] = val;
}
int len = values.Length;
Boolean caseInsensitive = false;
for (int i = 0; i < len; i++)
{
if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
//.........这里部分代码省略.........
示例10: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringCollection sc;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. Count on empty collection");
iCountTestcases++;
if (sc.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001, returned {0} for empty collection", sc.Count);
}
Console.WriteLine("2. add simple strings and verify Count");
strLoc = "Loc_002oo";
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
}
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002b, count is {0} instead of {1}", sc.Count, values.Length);
}
Console.WriteLine("3. add intl strings and verify Count");
strLoc = "Loc_003oo";
string [] intlValues = new string [values.Length];
for (int i = 0; i < values.Length; i++)
{
string val = intl.GetString(MAX_LEN, true, true, true);
while (Array.IndexOf(intlValues, val) != -1 )
val = intl.GetString(MAX_LEN, true, true, true);
intlValues[i] = val;
}
iCountTestcases++;
sc.Clear();
sc.AddRange(intlValues);
if ( sc.Count != intlValues.Length )
{
iCountErrors++;
Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, intlValues.Length);
}
iCountTestcases++;
sc.Clear();
sc.AddRange(intlValues);
if ( sc.Count != intlValues.Length )
{
iCountErrors++;
Console.WriteLine("Err_0003b, count is {0} instead of {1}", sc.Count, intlValues.Length);
}
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例11: AddRange_NullTest
public static void AddRange_NullTest(StringCollection collection, string[] data)
{
Assert.Throws<ArgumentNullException>("value", () => collection.AddRange(null));
}
示例12: PrintStringAtPos
public void PrintStringAtPos(string str, int pagenum, int col, int row, int maxlength = 100, int maxrows = 1)
{
if (String.IsNullOrWhiteSpace(str)) return;
// replace Euro with "{" {backspace} "=" as the best approximation i've come up with...
// unforunately the Euro currency came along after the printer's ROM... "{=" seemed to look the best out of various potential combinations, e.g. (=, C=, C:
str = str.Replace("€", "{\x08=");
//wordwrap logic...
if (str.Length > maxlength && Math.Abs(maxrows) > 1)
{
var lines = new StringCollection();
//first check if text already has hard coded carriage returns in it and just assume those have been formatted properly
if (str.Contains("\n")) lines.AddRange(str.Split('\n'));
else
{
//otherwise dive into word wrap logic...
//regex from here: http://regexlib.com/%28A%28EUjmatMAbqeJAVntKDWeVsP5A_5Xg2Q0u9xwCAHWWstjGAsCMb9Bvt6wVbYw4T-qTSvJU4RyVpn50P4Nci6N1vvxBArnwgO_k8F_3qJa5EdPPrrHHjp02XUS30FiGt4NNIFU8ZEynWmDksDVFHsuXNjDJ4ZS2saCasmnMl03WWfEW6uh7-BNkiTj0JD4Jypu0%29%29/REDetails.aspx?regexp_id=470
//grabs the 'maxlength' of chars it can, breaking on whitespace, period or dash
var wordWrapRegex =
new Regex(@"^[\s\S]{1," + maxlength.ToString(CultureInfo.InvariantCulture) + @"}([\s\.\-]|$)",
RegexOptions.Singleline | RegexOptions.ExplicitCapture);
while (lines.Count < Math.Abs(maxrows))
{
Match result = wordWrapRegex.Match(str);
if (!result.Success) break;
lines.Add(result.Value.TrimEnd());
str = str.Left(-result.Value.Length);
//negative Left "slices" x chars off the left and returns the remainder
}
//if we bailed out because we couldn't wordwrap anything in, just include the chopped text so at least it's visible
if (lines.Count < Math.Abs(maxrows) && str.Length > 0) lines.Add(str.Left(maxlength));
}
//negative maxrows means word wrap from the top of the block defined by row-lines.count
//e.g. when you're printing an NF1, Field 11 (the NF2 value box) has a "DO NOT GO OVER 2500" phrase that wraps within that space,
//so you want to "back up" to the top of the allocated text space and wrap down from there...
//conversely, when printing the flat NF2 dollar value, you want it to go right on the specified row at the bottom of the space
if (maxrows < 0) row = row - lines.Count + 1;
foreach (var line in lines)
PrintBytesAtPos(CP437GetBytes(line), pagenum, col, row++);
}
else
//otherwise just print the maxlength of single line
PrintBytesAtPos(CP437GetBytes(str.Left(maxlength)), pagenum, col, row);
}
示例13: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringCollection sc;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string[] destination;
int cnt = 0;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. Copy empty collection into empty array");
iCountTestcases++;
destination = new string[values.Length];
for (int i = 0; i < values.Length; i++)
{
destination[i] = "";
}
sc.CopyTo(destination, 0);
if( destination.Length != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0001a, altered array after copying empty collection");
}
if (destination.Length == values.Length)
{
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (String.Compare(destination[i], "", false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}b, item = \"{1}\" insteead of \"{2}\" after copying empty collection", i, destination[i], "");
}
}
}
Console.WriteLine("2. Copy empty collection into non-empty array");
iCountTestcases++;
destination = values;
sc.CopyTo(destination, 0);
if( destination.Length != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, altered array after copying empty collection");
}
if (destination.Length == values.Length)
{
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (String.Compare(destination[i], values[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty collection", i);
}
}
}
Console.WriteLine("3. add simple strings and CopyTo([], 0)");
strLoc = "Loc_003oo";
iCountTestcases++;
cnt = sc.Count;
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, values.Length);
}
destination = new string[values.Length];
sc.CopyTo(destination, 0);
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if ( String.Compare(sc[i], destination[i], false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i], sc[i]);
}
}
Console.WriteLine("4. add simple strings and CopyTo([], {0})", values.Length);
sc.Clear();
//.........这里部分代码省略.........
示例14: RemoveStopWords
///
/// Removes stop words from the text.
///
public static string RemoveStopWords(string inputText)
{
inputText = inputText
.Replace("\\", string.Empty)
.Replace("|", string.Empty)
.Replace("(", string.Empty)
.Replace(")", string.Empty)
.Replace("[", string.Empty)
.Replace("]", string.Empty)
.Replace("*", string.Empty)
.Replace("?", string.Empty)
.Replace("}", string.Empty)
.Replace("{", string.Empty)
.Replace("^", string.Empty)
.Replace("+", string.Empty);
// transform given text into array of words
char[] wordSeparators = new char[] { ' ', '\n', '\r', ',', ';', '.', '!', '?', '-', ' ', '"', '\'' };
string[] words = inputText.Split(wordSeparators, StringSplitOptions.RemoveEmptyEntries);
// Create and initializes a new StringCollection.
StringCollection myStopWordsCol = new StringCollection();
// Add a range of elements from an array to the end of the StringCollection.
myStopWordsCol.AddRange(stopWordsArrary);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < words.Length; i++)
{
string word = words[i].ToLowerInvariant().Trim();
if (word.Length > 1 && !myStopWordsCol.Contains(word))
sb.Append(word + " ");
}
return sb.ToString();
}
示例15: CommonConstructor
private void CommonConstructor(Ektron.Cms.Controls.Menu menuObject, Ektron.Cms.Common.EkEnumeration.CMSMenuItemType targettype, CMSIDTypes.menuitem_id targetid)
{
this.menu_id_val = new CMSIDTypes.menu_id(menuObject.DefaultMenuID);
this.targettype_val = targettype;
this.targetid_val = targetid;
MenuObj_val = menuObject;
// Test for standard menu XML xpaths
XmlNodeList xnl;
StringCollection strcolValidationPaths = new StringCollection();
string[] strarrValidationPaths = new string[] { "/MenuDataResult", "/MenuDataResult/Item", "/MenuDataResult/Item/Item" };
strcolValidationPaths.AddRange(strarrValidationPaths);
foreach (string strValidationPath in strcolValidationPaths)
{
xnl = MenuObj_val.XmlDoc.SelectNodes(strValidationPath);
if (xnl.Count <= 0)
{
TargetNotInMenuException ex = new TargetNotInMenuException(this.GetType().ToString() + ": CMS returns invalid menu data. XPath \"" + strValidationPath + "\" is missing from the XML returned for menu_id " + MenuObj_val.DefaultMenuID.ToString() + ". This may indicate that no menu with ID " + MenuObj_val.DefaultMenuID.ToString() + " exists.");
ex.Source = ExceptionSource;
throw (ex);
}
}
string menuTargetXPath = "/descendant::Item[child::ItemID=\'" + targetid.val.ToString() + "\' and ItemType=\'" + targettype.ToString() + "\']";
xnl = MenuObj_val.XmlDoc.SelectNodes(menuTargetXPath);
if (xnl.Count > 0) // Test to ensure that the target item exists in the menu
{
TargetCrumb_val = xnl[0];
}
else
{
TargetNotInMenuException ex = new TargetNotInMenuException(this.GetType().ToString() + ": Item ID " + targetid.val.ToString() + ", Type \"" + targettype.ToString() + "\" does not exist in menu_id " + MenuObj_val.DefaultMenuID.ToString());
ex.Source = ExceptionSource;
throw (ex);
}
string menuAncestorsXPath = "(" + menuTargetXPath + "/ancestor::Item[ItemType=\'" + Ektron.Cms.Common.EkEnumeration.CMSMenuItemType.Submenu.ToString() + "\'])|(" + menuTargetXPath + ")";
TierCrumb_val = MenuObj_val.XmlDoc.SelectNodes(menuAncestorsXPath);
TierCrumb_idx = new XMLNodeListIndexer(TierCrumb_val);
XmlNode xn;
Ektron.Cms.Common.EkEnumeration.CMSMenuItemType xn_ItemType;
int xn_ItemID;
string tierXPath;
int TierListLength;
if (targettype == Ektron.Cms.Common.EkEnumeration.CMSMenuItemType.Submenu)
{
//If target is a submenu we'll grab the children
TierListLength = TierCrumb_val.Count;
}
else
{
TierListLength = TierCrumb_val.Count - 1;
}
TierList_val = new XmlNodeList[TierListLength + 1];
for (int I = 0; I <= (TierListLength); I++)
{
if (I == 0)
{
xn = TierCrumb_val[0];
xn_ItemType = (Ektron.Cms.Common.EkEnumeration.CMSMenuItemType)(Enum.Parse(typeof(Ektron.Cms.Common.EkEnumeration.CMSMenuItemType), xn.SelectSingleNode("ItemType").InnerText));
xn_ItemID = int.Parse(xn.SelectSingleNode("ItemID").InnerText);
tierXPath = "/descendant::Item[child::ItemID=\'" + xn_ItemID.ToString() + "\' and ItemType=\'" + xn_ItemType.ToString() + "\']";
}
else if (TierCrumb_val.Count > 0)
{
xn = TierCrumb_val[I - 1];
xn_ItemType = (Ektron.Cms.Common.EkEnumeration.CMSMenuItemType)(Enum.Parse(typeof(Ektron.Cms.Common.EkEnumeration.CMSMenuItemType), xn.SelectSingleNode("ItemType").InnerText));
xn_ItemID = int.Parse((string)(xn.SelectSingleNode("ItemID").InnerText));
tierXPath = "/descendant::Item[child::ItemID=\'" + xn_ItemID.ToString() + "\' and ItemType=\'" + xn_ItemType.ToString() + "\']/child::Menu/child::Item";
break;
}
else
{
xn = TierCrumb_val[I];
xn_ItemType = (Ektron.Cms.Common.EkEnumeration.CMSMenuItemType)(Enum.Parse(typeof(Ektron.Cms.Common.EkEnumeration.CMSMenuItemType), xn.SelectSingleNode("ItemType").InnerText));
xn_ItemID = int.Parse(xn.SelectSingleNode("ItemID").InnerText);
tierXPath = "/descendant::Item[child::ItemID=\'" + xn_ItemID.ToString() + "\' and ItemType=\'" + xn_ItemType.ToString() + "\']/parent::Menu/child::Item";
}
xnl = MenuObj_val.XmlDoc.SelectNodes(tierXPath);
TierList_val.SetValue(xnl, I);
}
IsInitialized = true;
}