本文整理汇总了C#中System.String.Last方法的典型用法代码示例。如果您正苦于以下问题:C# String.Last方法的具体用法?C# String.Last怎么用?C# String.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Last方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(String[] args)
{
// This fixes the current directory in case it is run from outside the launcher path.
Environment.CurrentDirectory = Path.GetDirectoryName(typeof(SharpCraftApplication).Assembly.Location);
// Check for optional map specified to launch
string mapFile = ""; // Is there a loadfile arg specified?
for (var i = 0; i < args.Length; i++)
{
if (args[i] == "-loadfile" && args.Last() != "-loadfile") // if -loadfile and there are still more args to read
{
// check the argument immediately to the right... it should be a map file (w3x or w3m) or a replay (w3g)
if (args[i + 1].EndsWith(".w3x") || args[i + 1].EndsWith(".w3m") || args[i + 1].EndsWith(".w3g"))
{
mapFile = args[i + 1];
// clean string and wrap in quotes because path may contain spaces
// note: even when passing in the arg in quotes, those will "disappear", so quotes are re-applied
args[i + 1] = "\"" + args[i + 1].Trim() + "\"";
}
else
{
Console.WriteLine("The -loadfile param was specified, but was not immediately followed by a valid WarCraft map to open.");
}
}
else
{
Console.WriteLine("The -loadfile param was specified, but no more valid arguments follow it!");
}
}
if (args.Contains("-game") || args.Contains("-editor"))
{
Debug.WriteLineIf(args.Contains("-game"), args.Aggregate((a, b) => a + ' ' + b));
Debug.WriteLineIf(mapFile.Length > 0, "Starting game with map: " + mapFile);
StartDirect(args);
}
else
{
StartLauncher(args);
}
}
示例2: FindFile
public static String FindFile(String baseFolder, String fileName)
{
baseFolder = baseFolder.Replace('/', '\\');
if (baseFolder.Last() != '\\')
{
baseFolder += '\\';
}
var path = Path.Combine(baseFolder, fileName);
path = path.Replace('/', '\\');
var folder = Path.GetDirectoryName(fileName);
var file = Path.GetFileName(path);
var pathFolder = Path.GetDirectoryName(path);
if (!String.IsNullOrEmpty(pathFolder))
{
return Directory.GetFiles(pathFolder)
.FirstOrDefault(f => f.ToLower().Contains(Path.GetFileName(path).ToLower()));
}
return null;
}
示例3: Write
public void Write(String str)
{
this.FixStateToConsole();
this.CursorPosition = str
.Scan(this.CursorPosition, (p, c) => p.Move(c))
.StartWith(this.CursorPosition)
.EndWith(this.CursorPosition.Move(GetWidth(str)))
.Zip(str, Tuple.Create)
.Do(_ =>
{
System.Diagnostics.Debug.WriteLine(_);
this._cells[this.CursorIndex] = new Cell(_.Item2);
this.CursorIndex.CompareTo(this._buffer.Length).If(
i => i < 0,
i => this._buffer[this.CursorIndex] = _.Item2,
i => (i > 0
? this._buffer.Append(' ', this.CursorIndex - this._buffer.Length - 1)
: this._buffer
).Append(_.Item2)
);
if (this.IsVisible(_.Item1))
{
Console.SetCursorPosition(_.Item1.Left, _.Item1.Top);
Console.Write(_.Item2);
this.FixStateFromConsole();
}
})
.Last()
.Item1
.Move(str.Last());
this.FixStateFromConsole();
}
示例4: MakeRelativePath
/// <summary>
/// Creates a relative path from one file or folder to another.
/// </summary>
/// <param name="fromPath">Contains the directory that defines the start of the relative path.</param>
/// <param name="toPath">Contains the path that defines the endpoint of the relative path.</param>
/// <param name="dontEscape">Boolean indicating whether to add uri safe escapes to the relative path</param>
/// <returns>The relative path from the start directory to the end path.</returns>
/// <exception cref="ArgumentNullException"></exception>
public static String MakeRelativePath(String fromPath, String toPath)
{
if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
if (fromPath.Last() != '\\')
fromPath = fromPath + "\\";
Uri fromUri = new Uri(fromPath);
Uri toUri = new Uri(toPath);
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
return relativePath.Replace('/', Path.DirectorySeparatorChar);
}
示例5: SyncFolder
//<summary>Checks of the folder already exists as an album on flickr and synchronizes all folder in the current folder.</summary>
void SyncFolder(String path)
{
String[] picture_files = m_folder_enum.GetFilesOfType(path, m_pictures_suffixes);
if (!(path.Last() == Path.DirectorySeparatorChar))
path += Path.DirectorySeparatorChar;
String base_path = Path.GetDirectoryName(path).Split(Path.DirectorySeparatorChar).Last();
String photoset_id;
if (picture_files.Length < 1) return;
if (!m_flickr_connect.PhotoSetExists(base_path))
{
m_flickr_connect.AddSet(null, base_path, picture_files[0]);
picture_files = picture_files.Skip(1).ToArray();
}
photoset_id = m_flickr_connect.GetPhotoSetByName(base_path);
SyncFilesToSet(photoset_id, picture_files);
}
示例6: ParseSeconds
private static int ParseSeconds(String timespan)
{
const string format = "Timespan must be in the format <int>[unit] where unit is s, m, h";
if(String.IsNullOrEmpty(timespan))
{
throw new ArgumentException(format);
}
int multiplier = 1;
if(Char.IsLetter(timespan.Last()))
{
var units = new[] {'s', 'h', 'm'};
if(!units.Any(s => s == timespan.Last()))
{
throw new ArgumentException(format);
}
switch(timespan.Last())
{
case ('h'):
multiplier = 3600;
break;
case ('m'):
multiplier = 60;
break;
}
}
string amountString = timespan;
if(Char.IsLetter(timespan.Last()))
{
amountString = timespan.Remove(timespan.Length - 1);
}
int amount;
if(!int.TryParse(amountString, out amount))
{
throw new ArgumentException(format);
}
return amount * multiplier;
}
示例7: JoinClass
public FibeClass JoinClass(String[] path)
{
StringBuilder sb = new StringBuilder();
FibeClass c;
foreach (String s in path)
{
sb.Append(s);
if (s != path.Last()) sb.Append(", ");
}
if (classJoined.ContainsKey(sb.ToString()))
{
c = classJoined[sb.ToString()];
} else {
c = new FibeClass(path);
classJoined.Add(sb.ToString(), c);
c.client = this;
c.Title = sb.ToString() + " - " + sessionID;
c.connector = connector;
}
return c;
}
示例8: LoadData
private void LoadData()
{
var from = (IDictionary<string, object>)posts["from"];
InlineUIContainer uiContainer = new InlineUIContainer();
uiContainer.Child = new UserLinks((String)from["name"], -4);
Story.Inlines.Add(uiContainer);
string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", (String)from["id"], "square", _fb.AccessToken);
UserPic.Source = new BitmapImage(new Uri(profilePictureUrl));
String storytxt = "";
String story_tag = "";
dynamic selected_tagDic = null;
String message = "";
int message_tagsCount = 0;
try
{
storytxt = (String)posts["story"];
}
catch (Exception e) { }
try
{
if (((String)posts["type"]).Equals("link"))
{
var application = (IDictionary<string, object>)posts["application"];
if (((String)application["namespace"]).Equals("likes"))
{
storytxt = " likes a link.";
}
}
}
catch (Exception e) { }
IDictionary<string, object> message_tagsDic = null;
try
{
message_tagsDic = (IDictionary<string, object>)posts["message_tags"];
}
catch (Exception e) { }
try
{
var story_tagsDic = (IDictionary<string, object>)posts["story_tags"];
var story_tagsSecondEl = (IEnumerable<object>)story_tagsDic.ElementAt(1).Value;
var selected_tag = story_tagsSecondEl.ElementAt(0);
selected_tagDic = (IDictionary<string, object>)selected_tag;
story_tag = (String)selected_tagDic["name"]; ;
}
catch (Exception e) { }
try { message = (String)posts["message"]; }
catch (Exception e) { }
try
{
var message_tagsDicForCount = (IDictionary<string, object>)posts["message_tags"];
message_tagsCount = message_tagsDicForCount.Count;
}
catch (Exception e) { }
Run pText = new Run();
//pText.Foreground = new SolidColorBrush(Color.FromArgb(255, 129,129,129));
pText.Text = storytxt.Replace((String)from["name"], "");
Story.Inlines.Add(pText);
if (!story_tag.Equals(""))
{
String[] storyTextSplit = new String[] { storytxt.Substring(0, (int)selected_tagDic["offset"]), storytxt.Substring((int)selected_tagDic["offset"] + story_tag.Length) };
pText.Text = storyTextSplit[0].Replace((String)from["name"], "");
uiContainer = new InlineUIContainer();
uiContainer.Child = new UserLinks(story_tag, false, -4);
Story.Inlines.Add(uiContainer);
pText = new Run();
pText.Text = storyTextSplit.Last();
Story.Inlines.Add(pText);
}
if (message_tagsDic == null)
{
Run r = new Run();
r.Text = message;
Message.Inlines.Add(r);
}
else
{
String[] modMessage = new String[]{message};
Run r;
int offset = 0;
for (int i = 0; i < message_tagsDic.Count; i++)
{
var message_tagEl = (IEnumerable<object>)message_tagsDic.ElementAt(i).Value;
dynamic message_selTag = message_tagEl.ElementAt(0);
message_selTag = (IDictionary<string, object>)message_selTag;
String message_tagName = (String)message_selTag["name"];
modMessage = new String[] { modMessage[0].Substring(0, (int)message_selTag["offset"]-offset), modMessage[0].Substring((int)message_selTag["offset"] - offset + message_tagName.Length) };
offset = message_tagName.Length + (int)message_selTag["offset"];
//.........这里部分代码省略.........
示例9: loadSlideFolder
private void loadSlideFolder()
{
VarParser.XMLrequire(config, "conf");
IEnumerable<XElement> elements =
from el in config.Elements()
where el.Name == "includes"
select el;
XElement econf = elements.First();
VarParser.XMLrequire(econf, "includes");
elements =
from el in econf.Elements()
where el.Name == "slidefolder"
select el;
if(elements.Count() ==1)
if (elements.First().Attribute("src") != null)
{
slidefolder = elements.First().Attribute("src").Value.ToString();
if (slidefolder.Last() != '\\')
slidefolder = slidefolder + "\\";
if (!Directory.Exists(slidefolder) && ApplicationDeployment.IsNetworkDeployed)
slidefolder = ApplicationDeployment.CurrentDeployment.DataDirectory + "\\" + slidefolder;
Console.WriteLine("NEW SlideFolder: " + slidefolder);
}
}
示例10: ParseNum
protected Int32 ParseNum(String s)
{
Int32 value;
if(s.Length > 0 && s[0] == '$')
{
value = Int32.Parse(s.Substring(1), NumberStyles.HexNumber);
}
else if (s.Length > 2 && s[1] == 'x')
{
value = Int32.Parse(s.Substring(2), NumberStyles.HexNumber);
}
else if (s.Length > 1 && s.Last() == 'h' || s.Last() == 'H')
{
value = Int32.Parse(s.Substring(0, s.Length-1), NumberStyles.HexNumber);
}
else
{
value = Int32.Parse(s);
}
if (value > Int16.MaxValue || value < Int16.MinValue)
{
ErrorMsg("Integer cannot be represented in 16 bits");
}
return value;
}
示例11: Text
/// <summary>
/// Creates a <see cref="TextExpression"/> that represents a string or a character from specified source string.
/// </summary>
/// <param name="symbols">The symbol table for the expression.</param>
/// <param name="text">The string which contains quoting characters..</param>
/// <returns>An <see cref="TextExpression"/> which generates a string or a character from specified string.</returns>
public static TextExpression Text(SymbolTable symbols, String text)
{
return String.IsNullOrEmpty(text) || text.First() != text.Last()
? Text(symbols, default(Char), text)
: Text(symbols, text.First(), text.Substring(1, text.Length - 2));
}