本文整理汇总了C#中System.Collections.Specialized.StringCollection.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# StringCollection.RemoveAt方法的具体用法?C# StringCollection.RemoveAt怎么用?C# StringCollection.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.StringCollection
的用法示例。
在下文中一共展示了StringCollection.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluatePath
/// <summary>
/// Evaulate the path string in relation to the current item
/// </summary>
/// <param name="context">The Revolver context to evaluate the path against</param>
/// <param name="path">The path to evaulate. Can either be absolute or relative</param>
/// <returns>The full sitecore path to the target item</returns>
public static string EvaluatePath(Context context, string path)
{
if (ID.IsID(path))
return path;
string workingPath = string.Empty;
if (!path.StartsWith("/"))
workingPath = context.CurrentItem.Paths.FullPath + "/" + path;
else
workingPath = path;
// Strip any language and version tags
if (workingPath.IndexOf(':') >= 0)
workingPath = workingPath.Substring(0, workingPath.IndexOf(':'));
// Make relative paths absolute
string[] parts = workingPath.Split('/');
StringCollection targetParts = new StringCollection();
targetParts.AddRange(parts);
while (targetParts.Contains(".."))
{
int ind = targetParts.IndexOf("..");
targetParts.RemoveAt(ind);
if (ind > 0)
{
targetParts.RemoveAt(ind - 1);
}
}
if (targetParts[targetParts.Count - 1] == ".")
targetParts.RemoveAt(targetParts.Count - 1);
// Remove empty elements
while (targetParts.Contains(""))
{
targetParts.RemoveAt(targetParts.IndexOf(""));
}
string[] toRet = new string[targetParts.Count];
targetParts.CopyTo(toRet, 0);
return "/" + string.Join("/", toRet);
}
示例2: Initialize
/// ------------------------------------------------------------------------------------
/// <summary>
///
/// </summary>
/// ------------------------------------------------------------------------------------
public static StringCollection Initialize(StringCollection paths, int maxMruListSize)
{
MaxMRUListSize = maxMruListSize;
s_paths = (paths ?? new StringCollection());
RemoveStalePaths();
while (s_paths.Count > MaxMRUListSize)
s_paths.RemoveAt(s_paths.Count - 1);
return s_paths;
}
示例3: _aimTCGAServiceComboBox_KeyDown
private void _aimTCGAServiceComboBox_KeyDown(object sender, KeyEventArgs e)
{
if (_aimTCGAServiceComboBox.DroppedDown && _aimTCGAServiceComboBox.SelectedIndex != -1 && e.KeyCode == Keys.Delete)
{
e.Handled = true;
var sl = new StringCollection();
sl.AddRange(CollectionUtils.ToArray<string>(_component.AIMTCGAServiceList));
sl.RemoveAt(_aimTCGAServiceComboBox.SelectedIndex);
_component.AIMTCGAServiceList = sl;
}
}
示例4: ExpandMshGlobPath
//.........这里部分代码省略.........
pathResolutionTracer.WriteLine("Parent path: {0}", new object[] { path });
}
tracer.WriteLine("Base container path: {0}", new object[] { path });
if (stack.Count == 0)
{
string str3 = path;
if (provider2 != null)
{
str3 = provider2.GetChildName(path, context);
if (!string.IsNullOrEmpty(str3))
{
path = provider2.GetParentPath(path, null, context);
}
}
else
{
path = string.Empty;
}
stack.Push(str3);
pathResolutionTracer.WriteLine("Leaf element: {0}", new object[] { str3 });
}
pathResolutionTracer.WriteLine("Root path of resolution: {0}", new object[] { path });
}
currentDirs.Add(path);
while (stack.Count > 0)
{
if (context.Stopping)
{
throw new PipelineStoppedException();
}
string leafElement = stack.Pop();
currentDirs = this.GenerateNewPSPathsWithGlobLeaf(currentDirs, drive, leafElement, stack.Count == 0, provider, context);
if (stack.Count > 0)
{
using (pathResolutionTracer.TraceScope("Checking matches to ensure they are containers", new object[0]))
{
int index = 0;
while (index < currentDirs.Count)
{
if (context.Stopping)
{
throw new PipelineStoppedException();
}
string mshQualifiedPath = GetMshQualifiedPath(currentDirs[index], drive);
if ((provider2 != null) && !this.sessionState.Internal.IsItemContainer(mshQualifiedPath, context))
{
tracer.WriteLine("Removing {0} because it is not a container", new object[] { currentDirs[index] });
pathResolutionTracer.WriteLine("{0} is not a container", new object[] { currentDirs[index] });
currentDirs.RemoveAt(index);
}
else if (provider2 != null)
{
pathResolutionTracer.WriteLine("{0} is a container", new object[] { currentDirs[index] });
index++;
}
}
continue;
}
}
}
foreach (string str6 in currentDirs)
{
pathResolutionTracer.WriteLine("RESOLVED PATH: {0}", new object[] { str6 });
collection.Add(str6);
}
return collection;
}
string str7 = context.SuppressWildcardExpansion ? path : RemoveGlobEscaping(path);
string format = OSHelper.IsUnix && provider.GetType () == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) ? (str7.StartsWith ("/") ? "{1}" : "{0}/{1}") : "{0}:" + '\\' + "{1}";
if (drive.Hidden)
{
if (IsProviderDirectPath(str7))
{
format = "{1}";
}
else
{
format = "{0}::{1}";
}
}
else
{
char ch = OSHelper.IsUnix && provider.GetType () == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) ? '/' : '\\';
if (path.StartsWith(ch.ToString(), StringComparison.Ordinal))
{
format = OSHelper.IsUnix && provider.GetType () == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) ? "{1}" : "{0}:{1}";
}
}
string str9 = string.Format(CultureInfo.InvariantCulture, format, new object[] { drive.Name, str7 });
if (allowNonexistingPaths || provider.ItemExists(this.GetProviderPath(str9, context), context))
{
pathResolutionTracer.WriteLine("RESOLVED PATH: {0}", new object[] { str9 });
collection.Add(str9);
return collection;
}
ItemNotFoundException exception2 = new ItemNotFoundException(str9, "PathNotFound", SessionStateStrings.PathNotFound);
pathResolutionTracer.TraceError("Item does not exist: {0}", new object[] { path });
throw exception2;
}
}
示例5: UpdateList
/// <summary>
/// This method updates the cache and hak list properties in the module
/// info, adding the passed array of strings to the appropriate property.
/// Both of these lists consist of an array of structures with 1 string
/// item in each struture.
/// </summary>
/// <param name="listTag">The property name for the list</param>
/// <param name="entryTag">The property name for each string in the list's
/// structures</param>
/// <param name="structID">The structure ID of the structures in the list</param>
/// <param name="stringType">The data type of the string in the list, either
/// ExoString or ResRef</param>
/// <param name="values">The array of strings to add, duplicates are pruned</param>
private void UpdateList(string listTag, string entryTag, uint structID,
GffFieldType stringType, string[] values)
{
// Get the array of elements in the list.
GffListField listField = (GffListField) GetField(properties[listTag]);
GffFieldCollection list = listField.Value;
// Create a string collection containing lower case copies of all of
// the strings.
StringCollection strings = new StringCollection();
strings.AddRange(values);
for (int i = 0; i < strings.Count; i ++)
strings[i] = strings[i].ToLower();
// Make a first pass and eliminate any strings that are already
// in the module.
foreach (GffStructField field in list)
{
// Get the string entry for the value.
GffFieldDictionary dict = field.Value;
GffField structValue = dict[entryTag];
// Check to see if the hak is in the list of haks to add if it is
// then remove it.
int index = strings.IndexOf((string) structValue.Value);
if (-1 != index) strings.RemoveAt(index);
}
// Now loop through all of the remaining strings and add them to the
// beginning of the list. We walk the list backwards adding the items
// to the beginning of the list's collection, so when we are done
// all of the added items are in order at the FRONT of the list.
for (int i = strings.Count - 1; i >= 0; i--)
{
// Create a ExoString field for the hak file name.
GffField structValue = GffFieldFactory.CreateField(stringType);
structValue.Value = strings[i];
// Create a GffStructField for the new list element and
// save the exoString hak name in it.
GffStructField listStruct = (GffStructField)
GffFieldFactory.CreateField(GffFieldType.Struct);
listStruct.StructureType = structID;
listStruct.Value = new GffFieldDictionary();
listStruct.Value.Add(entryTag, structValue);
// Add the structure to the list.
list.Insert(0, listStruct);
}
}
示例6: Test01
public void Test01()
{
IntlStrings intl;
StringCollection sc;
// simple string values
string[] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// [] initialize IntStrings
intl = new IntlStrings();
// [] StringCollection is constructed as expected
//-----------------------------------------------------------------
sc = new StringCollection();
// [] RemoveAt() for empty collection
//
if (sc.Count > 0)
sc.Clear();
Assert.Throws<ArgumentOutOfRangeException>(() => { sc.RemoveAt(0); });
// [] RemoveAt() on filled collection
//
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length));
}
sc.RemoveAt(0);
if (sc.Count != values.Length - 1)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", sc.Count, values.Length - 1));
}
if (sc.Contains(values[0]))
{
Assert.False(true, string.Format("Error, removed wrong item"));
}
// check that all init items were moved
for (int i = 0; i < values.Length; i++)
{
if (sc.IndexOf(values[i]) != i - 1)
{
Assert.False(true, string.Format("Error, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i - 1));
}
}
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length));
}
sc.RemoveAt(values.Length - 1);
if (sc.Count != values.Length - 1)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", sc.Count, values.Length - 1));
}
if (sc.Contains(values[values.Length - 1]))
{
Assert.False(true, string.Format("Error, removed wrong item"));
}
// check that all init items were moved
for (int i = 0; i < values.Length - 1; i++)
{
if (sc.IndexOf(values[i]) != i)
{
Assert.False(true, string.Format("Error, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i));
}
}
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
//.........这里部分代码省略.........
示例7: generate_dataemail_processingfileMaster
/// <summary>
/// main method of the thread, generates a master report
/// </summary>
/// <param name="report_params"></param>
private void generate_dataemail_processingfileMaster(report_values report_params)
{
datamgmt.process_responses processing_files = new datamgmt.process_responses(true);
processing_files.permss_user = report_params.permss_user;
processing_files.permss_admin = report_params.permss_admin;
processing_files.questionnaire_id = report_params.questionnaire_id;
processing_files.from = report_params.from;
processing_files.until = report_params.until;
processing_files.questionnaire_title = report_params.questionnaire_title;
processing_files.pathtotempdir = report_params.pathtotempdir;
processing_files.Master = report_params.Master;
processing_files.IsmasterReport = report_params.IsMasterReport;
if(report_params.scheduled)
processing_files.IsMasterFail = processing_files.Master.ValidateMaster();
StringCollection file_names = new StringCollection();
int record_counter = 0;
string zip_name = "";
if (!processing_files.IsMasterFail)
{
file_names = processing_files.generate();
//read number of records and delete entry in file_names
record_counter = Int32.Parse(file_names[0]);
file_names.RemoveAt(0);
#region create zip file
string timeformat = "yyyyMMddHHmmss";
zip_name = String.Format("zip_{0}_{1}.zip", report_params.Master.Dto.MasterRptId, DateTime.Now.ToString(timeformat));
utility.createZIP(zip_name, report_params.pathtotempdir, file_names);
#endregion
}
#region create and send email
MailMessage msg = new MailMessage();
//.NET 1.1: msg.BodyFormat = MailFormat.Html;
msg.IsBodyHtml = true;
//.NET 1.1: msg.From = email_from;
msg.From = new MailAddress(email_from);
//.NET 1.1: msg.To = report_params.permss_user;
//MailAddressCollection to = msg.To;
utility.set_Mail_address(ref msg, "to", report_params.permss_user);
//to.Add(report_params.permss_user);
if (processing_files.IsMasterFail)
{
msg.Subject = String.Format("RFG - FAILURE - combined response file report for master report {0}", report_params.Master.Dto.MasterName);
}
else
{
msg.Subject = String.Format("RFG - combined response file report for master report {0}", report_params.Master.Dto.MasterName);
}
if (record_counter > 0)
{
//.NET 1.1: MailAttachment response_files = new MailAttachment(report_params.pathtotempdir + zip_name);
Attachment response_files = new Attachment(report_params.pathtotempdir + zip_name);
msg.Attachments.Add(response_files);
}
#region building emails content (information about the responsefiles)
//††† 20120302 Biju Pattathil | RFG2.7 PR629425:dts email having wrong RFG support link (RFG Support link will change):Start†††
string support_url = utility.getParameter("support_link"); //+ "live/index.aspx?qid=1493&flexfield1=stop_scheduled_report&flexfield14=qid-" + report_params.questionnaire_id + "-sid-" + report_params.schedule_id + "&flexfield15=" + report_params.permss_user;
string mail_text = @"
<style>
body {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;}
table {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;}
p {font-family:""Arial"";font-weight:normal;color:black;margin-top: -5px}
b {font-family:""Arial"";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:""Arial"";font-weight:normal;font-size:14pt;color:black }
H2 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:maroon }
H3 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:darkgreen }
pre {font-family:""Arial Console"";font-size: .9em}
.head{ font-family:""Arial"";font-weight:bold;font-size:10pt;color:red }
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>";
if (report_params.scheduled)
{
//Commented by Phani for RFG 1.9.4 release
//.........这里部分代码省略.........
示例8: GetTemplatesWithParams
/// <summary>Returns the array of strings, containing templates, used on page
/// (applied to page). Everything inside braces is returned with all parameters
/// untouched. Links to templates (like [[:Template:...]]) are not returned. Templates,
/// mentioned inside <nowiki></nowiki> tags are also not returned. The "magic words"
/// (see http://meta.wikimedia.org/wiki/Help:Magic_words) are recognized and
/// not returned by this function as templates. When using this function on text of the
/// template, parameters names and numbers (like {{{link}}} and {{{1}}}) are not returned
/// by this function as templates too.</summary>
/// <returns>Returns the string[] array.</returns>
public string[] GetTemplatesWithParams()
{
Dictionary<int, int> templPos = new Dictionary<int, int>();
StringCollection templates = new StringCollection();
int startPos, endPos, len = 0;
string str = text;
while ((startPos = str.LastIndexOf("{{")) != -1) {
endPos = str.IndexOf("}}", startPos);
len = (endPos != -1) ? endPos - startPos + 2 : 2;
if (len != 2)
templPos.Add(startPos, len);
str = str.Remove(startPos, len);
str = str.Insert(startPos, new String('_', len));
}
string[] templTitles = GetTemplates(false);
Array.Reverse(templTitles);
foreach (KeyValuePair<int, int> pos in templPos)
templates.Add(text.Substring(pos.Key + 2, pos.Value - 4));
for (int i = 0; i < templTitles.Length; i++)
while (i < templates.Count &&
!templates[i].StartsWith(templTitles[i]) &&
!templates[i].StartsWith(site.namespaces["10"].ToString() + ":" +
templTitles[i], true, site.langCulture) &&
!templates[i].StartsWith(Site.wikiNSpaces["10"].ToString() + ":" +
templTitles[i], true, site.langCulture) &&
!templates[i].StartsWith("msgnw:" + templTitles[i]))
templates.RemoveAt(i);
string[] arr = new string[templates.Count];
templates.CopyTo(arr, 0);
Array.Reverse(arr);
return arr;
}
示例9: AddRecentlyUsedFile
public void AddRecentlyUsedFile(FileInfo newFile) {
StringCollection recent = new StringCollection();
recent.AddRange(data.RecentOpenedFiles);
while(recent.IndexOf(newFile.FullName) >= 0) {
recent.Remove(newFile.FullName);
}
recent.Insert(0, newFile.FullName);
while (recent.Count > 16) {
recent.RemoveAt(16);
}
string[] result = new string[recent.Count];
recent.CopyTo(result, 0);
data.RecentOpenedFiles = result;
}
示例10: Test01
//.........这里部分代码省略.........
//
bool res = en.MoveNext();
if (res)
{
Assert.False(true, string.Format("Error, MoveNext returned true"));
}
//
// Attempt to get Current should result in exception
//
Assert.Throws<InvalidOperationException>(() => { curr = en.Current; });
//
// Filled collection
// [] Enumerator for filled collection
//
sc.AddRange(values);
en = sc.GetEnumerator();
type = en.GetType().ToString();
if (type.IndexOf("StringEnumerator", 0) == 0)
{
Assert.False(true, string.Format("Error, type is not StringEnumerator"));
}
//
// MoveNext should return true
//
for (int i = 0; i < sc.Count; i++)
{
res = en.MoveNext();
if (!res)
{
Assert.False(true, string.Format("Error, MoveNext returned false", i));
}
curr = en.Current;
if (String.Compare(curr, sc[i]) != 0)
{
Assert.False(true, string.Format("Error, Current returned \"{1}\" instead of \"{2}\"", i, curr, sc[i]));
}
// while we didn't MoveNext, Current should return the same value
string curr1 = en.Current;
if (String.Compare(curr, curr1) != 0)
{
Assert.False(true, string.Format("Error, second call of Current returned different result", i));
}
}
// next MoveNext should bring us outside of the collection
//
res = en.MoveNext();
res = en.MoveNext();
if (res)
{
Assert.False(true, string.Format("Error, MoveNext returned true"));
}
//
// Attempt to get Current should result in exception
//
Assert.Throws<InvalidOperationException>(() => { curr = en.Current; });
en.Reset();
//
// Attempt to get Current should result in exception
//
Assert.Throws<InvalidOperationException>(() => { curr = en.Current; });
//
// [] Modify collection when enumerating
//
if (sc.Count < 1)
sc.AddRange(values);
en = sc.GetEnumerator();
res = en.MoveNext();
if (!res)
{
Assert.False(true, string.Format("Error, MoveNext returned false"));
}
int cnt = sc.Count;
sc.RemoveAt(0);
if (sc.Count != cnt - 1)
{
Assert.False(true, string.Format("Error, didn't remove 0-item"));
}
// will return just removed item
curr = en.Current;
if (String.Compare(curr, values[0]) != 0)
{
Assert.False(true, string.Format("Error, current returned {0} instead of {1}", curr, values[0]));
}
// exception expected
Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); });
}
示例11: ExtractObjectTypeNameFrom
private string ExtractObjectTypeNameFrom(StringCollection elementsList) {
if (elementsList.Count <= 1)
return null;
string typeName = elementsList[0];
elementsList.RemoveAt(0);
return GetCheckedTypeNameBy(typeName);
}
示例12: ExpandGlobPath
//.........这里部分代码省略.........
}
string a = provider2.GetParentPath(path, root, context);
if (string.Equals(a, path, StringComparison.OrdinalIgnoreCase))
{
throw PSTraceSource.NewInvalidOperationException("SessionStateStrings", "ProviderImplementationInconsistent", new object[] { provider.ProviderInfo.Name, path });
}
path = a;
}
else
{
path = string.Empty;
}
tracer.WriteLine("New path: {0}", new object[] { path });
pathResolutionTracer.WriteLine("Parent path: {0}", new object[] { path });
}
tracer.WriteLine("Base container path: {0}", new object[] { path });
if (stack.Count == 0)
{
string str7 = path;
if (provider2 != null)
{
str7 = provider2.GetChildName(path, context);
if (!string.IsNullOrEmpty(str7))
{
path = provider2.GetParentPath(path, null, context);
}
}
else
{
path = string.Empty;
}
stack.Push(str7);
pathResolutionTracer.WriteLine("Leaf element: {0}", new object[] { str7 });
}
pathResolutionTracer.WriteLine("Root path of resolution: {0}", new object[] { path });
}
currentDirs.Add(path);
while (stack.Count > 0)
{
if (context.Stopping)
{
throw new PipelineStoppedException();
}
string leafElement = stack.Pop();
currentDirs = this.GenerateNewPathsWithGlobLeaf(currentDirs, leafElement, stack.Count == 0, provider, context);
if (stack.Count > 0)
{
using (pathResolutionTracer.TraceScope("Checking matches to ensure they are containers", new object[0]))
{
int index = 0;
while (index < currentDirs.Count)
{
if (context.Stopping)
{
throw new PipelineStoppedException();
}
if ((provider2 != null) && !provider2.IsItemContainer(currentDirs[index], context))
{
tracer.WriteLine("Removing {0} because it is not a container", new object[] { currentDirs[index] });
pathResolutionTracer.WriteLine("{0} is not a container", new object[] { currentDirs[index] });
currentDirs.RemoveAt(index);
}
else if (provider2 != null)
{
pathResolutionTracer.WriteLine("{0} is a container", new object[] { currentDirs[index] });
index++;
}
}
continue;
}
}
}
foreach (string str9 in currentDirs)
{
pathResolutionTracer.WriteLine("RESOLVED PATH: {0}", new object[] { str9 });
collection.Add(str9);
}
}
else
{
string str10 = context.SuppressWildcardExpansion ? path : RemoveGlobEscaping(path);
if (allowNonexistingPaths || provider.ItemExists(str10, context))
{
pathResolutionTracer.WriteLine("RESOLVED PATH: {0}", new object[] { str10 });
collection.Add(str10);
}
else
{
ItemNotFoundException exception2 = new ItemNotFoundException(path, "PathNotFound", SessionStateStrings.PathNotFound);
pathResolutionTracer.TraceError("Item does not exist: {0}", new object[] { path });
throw exception2;
}
}
}
if (flag)
{
context.Filter = filter;
}
return collection;
}
示例13: RemoveParameter
/// <summary>
/// Remove an element from an array by value and optionally a number of elements after it.
/// </summary>
/// <param name="array">The array to remove the value from</param>
/// <param name="value">The value to remove</param>
/// <param name="count">The number of elements after the value to remove aswell</param>
/// <returns>An array without the value</returns>
public static string[] RemoveParameter(string[] array, string value, int count)
{
if (Array.IndexOf(array, value) < 0)
return array;
else
{
StringCollection coll = new StringCollection();
coll.AddRange(array);
int ind = coll.IndexOf(value);
for (int i = ind + count; i >= ind; i--)
coll.RemoveAt(ind);
string[] output = new string[coll.Count];
coll.CopyTo(output, 0);
return output;
}
}
示例14: smethod_7
// Token: 0x06001234 RID: 4660
// RVA: 0x0006137C File Offset: 0x0005F57C
public static void smethod_7(StringCollection stringCollection_0, Class158 class158_0, Class157 class157_0)
{
if (class157_0 != null)
{
class158_0.Remove(class157_0);
int i = int.Parse(class157_0.Value);
stringCollection_0.RemoveAt(i);
while (i < stringCollection_0.Count)
{
if (Class174.smethod_2(stringCollection_0[i]))
{
break;
}
if (stringCollection_0[i][0] != '\t' && stringCollection_0[i][0] != ' ')
{
return;
}
stringCollection_0.RemoveAt(i);
}
}
}
示例15: Parse
// ヘッダを分析し、Dictionary<string, string> に格納
public static Dictionary<string, string> Parse(string header)
{
StringCollection line = new StringCollection();
Dictionary<string, string> sd = new Dictionary<string, string>();
line.AddRange(Regex.Split(header, "\r\n"));
Match m = Regex.Match(line[0], @"^(.+)\s+(.+)/(\d\.\d)$");
Match n = Regex.Match(line[0], @"^(.+)/(\d\.\d)\s+(\d{3})\s+(.+)$");
if (m.Success)
{ // REQUEST - e.g.: "^(GET String) (SHIORI)/(2.5)$"
sd["_COMMANDLINE_"] = line[0];
sd["_METHOD_"] = m.Groups[1].Value;
sd["_PROTOCOL_"] = m.Groups[2].Value;
sd["_VERSION_"] = m.Groups[3].Value;
}
else if (n.Success)
{ // RESPONSE - e.g.: "^(SHIORI)/(3.0) (204) (No Content)$"
sd["_STATUSLINE_"] = line[0];
sd["_PROTOCOL_"] = n.Groups[1].Value;
sd["_VERSION_"] = n.Groups[2].Value;
sd["_STATUS_"] = n.Groups[3].Value;
sd["_STRING_"] = n.Groups[4].Value;
}
line.RemoveAt(0); // コマンドライン削除
// SSTP の Entry, IfGhost - Script は例外にならざるを得ないので、このような処理になった
// その他の方法論としては、レスポンス格納用の変数をさらにネストするか、
// 行単位で保持するか、独自の管理クラスを作るか、
// そもそも帰ってきた値を変数としてキープしておくのをやめるか、等々
// int e = 0; // Entryキー用カウンタ
// int i = 0; // IfGhost 用カウンタ
// int s = 0; // Script 用カウンタ
// Regex re = new Regex(@"^Entry\s*:\s*(.+)\s*$", RegexOptions.Compiled);
// Regex ri = new Regex(@"^IfGhost\s*:\s*(.+)\s*$", RegexOptions.Compiled);
// Regex rs = new Regex(@"^Script\s*:\s*(.+)\s*$", RegexOptions.Compiled);
// Regex rg = new Regex(@"^GhostEx\s*:\s*(.+)\s*$", RegexOptions.Compiled);
// Regex rb = new Regex(@"^X-Bottle-IfGhost\s*:\s*(.+)\s*$", RegexOptions.Compiled); // ボトル拡張
for (int j = 0; j < line.Count; ++j)
{
m = Protocol.rGeneralEntry.Match(line[j]);
if (m.Success)
{ // e.g.: "^Value: \0\s[10]Hello, World!\e"
sd[m.Groups[1].Value] = m.Groups[2].Value.Trim();
// } else if (re.Match(c).Success) { // "Entry: SAKURA script"
// sd["Entry" + e++] = re.Match(c).Groups[1].Value;
// } else if (ri.Match(c).Success) { // "IfGhost: Ghost name(s)"
// sd["IfGhost" + i++] = ri.Match(c).Groups[1].Value;
// } else if (rs.Match(c).Success) { // "Script: SAKURA script"
// sd["GhostEx" + s++] = rs.Match(c).Groups[1].Value;
// } else if (rg.Match(c).Success) { // "GhostEx: Ghost name"
// sd["Script" + s++] = rg.Match(c).Groups[1].Value;
// } else if (rb.Match(c).Success) { // "X-Bottle-IfGhost: Ghost name"
// sd["X-Bottle-IfGhost"] = rb.Match(c).Groups[1].Value;
}
}
return sd;
}