本文整理汇总了C#中String.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# String.ElementAt方法的具体用法?C# String.ElementAt怎么用?C# String.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.ElementAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AllPermutations
// Returns all permutation of 'str'
public static List<string> AllPermutations(List<string> list, String start, String str)
{
if (str.Length <= 1)
list.Add(start + str);
else
for (int i = 0; i < str.Length; i++)
{
String newStr = str.Substring(0, i) + str.Substring(i + 1);
AllPermutations(list, start + str.ElementAt(i), newStr);
}
return list;
}
示例2: handleChatInput
protected void handleChatInput(String line)
{
if (line.Length > 0)
{
if (quitHelperMessageShow && (line == "q" || line == "Q"))
{
Console.WriteLine();
enqueuePluginChatMessage("If you are trying to quit, use the /quit command.", true);
quitHelperMessageShow = false;
}
if (line.ElementAt(0) == '/')
{
String line_lower = line.ToLower();
if (line_lower == "/quit")
{
intentionalConnectionEnd = true;
endSession = true;
sendConnectionEndMessage("Quit");
}
else if (line_lower == "/crash")
{
Object o = null;
o.ToString();
}
else if (line_lower == "/ping")
{
if (!pingStopwatch.IsRunning)
{
sendMessageTCP(KLFCommon.ClientMessageID.PING, null);
pingStopwatch.Start();
}
}
else if (line_lower.Length > (KLFCommon.SHARE_CRAFT_COMMAND.Length + 1)
&& line_lower.Substring(0, KLFCommon.SHARE_CRAFT_COMMAND.Length) == KLFCommon.SHARE_CRAFT_COMMAND)
{
//Share a craft file
String craft_name = line.Substring(KLFCommon.SHARE_CRAFT_COMMAND.Length + 1);
byte craft_type = 0;
String filename = findCraftFilename(craft_name, ref craft_type);
if (filename != null && filename.Length > 0)
{
try
{
byte[] craft_bytes = File.ReadAllBytes(filename);
sendShareCraftMessage(craft_name, craft_bytes, craft_type);
}
catch
{
enqueueTextMessage("Error reading craft file: " + filename);
}
}
else
enqueueTextMessage("Craft file not found: " + craft_name);
}
}
else
{
sendTextMessage(line);
}
}
}
示例3: HandleChatInput
protected void HandleChatInput(String line)
{
if(line.Length > 0 && line.ElementAt(0) == '/')
{
String[] InputArgs = line.Split(' ');
switch(InputArgs[0].ToLowerInvariant())
{
case "/quit":
IntentionalConnectionEnd = true;
EndSession = true;
SendConnectionEndMessage("Quit");
break;
case "/crash":
Object o = null;
o.ToString();
break;
case "/ping":
if (!PingStopwatch.IsRunning)
{
SendMessageTcp(KLFCommon.ClientMessageID.Ping, null);
PingStopwatch.Start();
}
break;
case KLFCommon.ShareCraftCommand:
if(InputArgs.Length > 1)
{
String craftName = String.Join(" ", InputArgs, 1, InputArgs.Length - 2);
byte craftType = 0;
String filename = FindCraftFilename(craftName, ref craftType);
if (filename != null && filename.Length > 0)
{
try
{
byte[] craftBytes = File.ReadAllBytes(filename);
SendShareCraftMessage(craftName, craftBytes, craftType);
}
catch
{
EnqueueTextMessage("Error reading craft file: " + filename);
}
}
else
EnqueueTextMessage("Craft file not found: " + craftName);
}
break;
default:
EnqueueTextMessage("Unrecognized command: " + InputArgs[0]);
break;
}
}
else
SendTextMessage(line);
}