本文整理匯總了C#中System.String.LastIndexOfAny方法的典型用法代碼示例。如果您正苦於以下問題:C# String.LastIndexOfAny方法的具體用法?C# String.LastIndexOfAny怎麽用?C# String.LastIndexOfAny使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.String
的用法示例。
在下文中一共展示了String.LastIndexOfAny方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: NewAttachment
public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
{
if (type != AttachmentType.region)
throw new Exception("Unknown attachment type: " + type);
// Strip folder names.
int index = name.LastIndexOfAny(new char[] {'/', '\\'});
if (index != -1)
name = name.Substring(index + 1);
tk2dSpriteDefinition def = sprites.GetSpriteDefinition(name);
if (def == null)
throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")");
if (def.complexGeometry)
throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")");
if (def.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW)
throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")");
RegionAttachment attachment = new RegionAttachment(name);
Vector2 minTexCoords = Vector2.one;
Vector2 maxTexCoords = Vector2.zero;
for (int i = 0; i < def.uvs.Length; ++i) {
Vector2 uv = def.uvs[i];
minTexCoords = Vector2.Min(minTexCoords, uv);
maxTexCoords = Vector2.Max(maxTexCoords, uv);
}
bool rotated = def.flipped == tk2dSpriteDefinition.FlipMode.Tk2d;
if (rotated) {
float temp = minTexCoords.x;
minTexCoords.x = maxTexCoords.x;
maxTexCoords.x = temp;
}
attachment.SetUVs(
minTexCoords.x,
maxTexCoords.y,
maxTexCoords.x,
minTexCoords.y,
rotated
);
attachment.RegionOriginalWidth = (int)(def.untrimmedBoundsData[1].x / def.texelSize.x);
attachment.RegionOriginalHeight = (int)(def.untrimmedBoundsData[1].y / def.texelSize.y);
attachment.RegionWidth = (int)(def.boundsData[1].x / def.texelSize.x);
attachment.RegionHeight = (int)(def.boundsData[1].y / def.texelSize.y);
float x0 = def.untrimmedBoundsData[0].x - def.untrimmedBoundsData[1].x / 2;
float x1 = def.boundsData[0].x - def.boundsData[1].x / 2;
attachment.RegionOffsetX = (int)((x1 - x0) / def.texelSize.x);
float y0 = def.untrimmedBoundsData[0].y - def.untrimmedBoundsData[1].y / 2;
float y1 = def.boundsData[0].y - def.boundsData[1].y / 2;
attachment.RegionOffsetY = (int)((y1 - y0) / def.texelSize.y);
attachment.RendererObject = def.material;
return attachment;
}
示例2: NewAttachment
public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
{
if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type);
// Strip folder names.
int index = name.LastIndexOfAny(new char[] {'/', '\\'});
if (index != -1) name = name.Substring(index + 1);
tk2dSpriteDefinition attachmentParameters = null;
for (int i = 0; i < sprites.inst.spriteDefinitions.Length; ++i) {
tk2dSpriteDefinition def = sprites.inst.spriteDefinitions[i];
if (def.name == name) {
attachmentParameters = def;
break;
}
}
if (attachmentParameters == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")");
if (attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")");
if (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")");
Vector2 minTexCoords = Vector2.one;
Vector2 maxTexCoords = Vector2.zero;
for (int i = 0; i < attachmentParameters.uvs.Length; ++i) {
Vector2 uv = attachmentParameters.uvs[i];
minTexCoords = Vector2.Min(minTexCoords, uv);
maxTexCoords = Vector2.Max(maxTexCoords, uv);
}
Texture texture = attachmentParameters.material.mainTexture;
int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * texture.width);
int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * texture.height);
bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d);
if (rotated) {
float temp = minTexCoords.x;
minTexCoords.x = maxTexCoords.x;
maxTexCoords.x = temp;
}
RegionAttachment attachment = new RegionAttachment(name);
attachment.SetUVs(
minTexCoords.x,
maxTexCoords.y,
maxTexCoords.x,
minTexCoords.y,
rotated
);
// TODO - Set attachment.RegionOffsetX/Y. What units does attachmentParameters.untrimmedBoundsData use?!
attachment.RegionWidth = width;
attachment.RegionHeight = height;
attachment.RegionOriginalWidth = width;
attachment.RegionOriginalHeight = height;
return attachment;
}
示例3: StatManager
public StatManager(String SaveStatePath)
{
if (string.IsNullOrEmpty(SaveStatePath)) { logger.Error("SaveStatePath was null or empty."); throw new ArgumentNullException("SaveStatePath Can't be Null or Empty String. "); }
if (SaveStatePath.LastIndexOfAny(Path.GetInvalidPathChars()) >= 0) { logger.Error("Invalid Path Characters In SaveStatePath=\"{0}\")", SaveStatePath); throw new ArgumentException("Invalid Characters In Path"); }
if (SaveStatePath.Any( x => char.IsWhiteSpace ( x ))) { logger.Error("Whitespace Characters In SaveStatePath=\"{0}\" ", SaveStatePath); throw new ArgumentException("WhiteSpace Characters In Path"); }
logger.Info("Called with (SaveStatePath=\"{0}\")", SaveStatePath);
LoadSaveState(SaveStatePath);
_savestatepath = SaveStatePath;
}
示例4: ProcessSpriteDefinition
private void ProcessSpriteDefinition (String name) {
// Strip folder names.
int index = name.LastIndexOfAny(new char[] {'/', '\\'});
if (index != -1)
name = name.Substring(index + 1);
tk2dSpriteDefinition def = sprites.inst.GetSpriteDefinition(name);
if (def == null) {
Debug.Log("Sprite not found in atlas: " + name, sprites);
throw new Exception("Sprite not found in atlas: " + name);
}
if (def.complexGeometry)
throw new NotImplementedException("Complex geometry is not supported: " + name);
if (def.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW)
throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name);
Vector2 minTexCoords = Vector2.one, maxTexCoords = Vector2.zero;
for (int i = 0; i < def.uvs.Length; ++i) {
Vector2 uv = def.uvs[i];
minTexCoords = Vector2.Min(minTexCoords, uv);
maxTexCoords = Vector2.Max(maxTexCoords, uv);
}
regionRotated = def.flipped == tk2dSpriteDefinition.FlipMode.Tk2d;
if (regionRotated) {
float temp = minTexCoords.x;
minTexCoords.x = maxTexCoords.x;
maxTexCoords.x = temp;
}
u = minTexCoords.x;
v = maxTexCoords.y;
u2 = maxTexCoords.x;
v2 = minTexCoords.y;
regionOriginalWidth = (int)(def.untrimmedBoundsData[1].x / def.texelSize.x);
regionOriginalHeight = (int)(def.untrimmedBoundsData[1].y / def.texelSize.y);
regionWidth = (int)(def.boundsData[1].x / def.texelSize.x);
regionHeight = (int)(def.boundsData[1].y / def.texelSize.y);
float x0 = def.untrimmedBoundsData[0].x - def.untrimmedBoundsData[1].x / 2;
float x1 = def.boundsData[0].x - def.boundsData[1].x / 2;
regionOffsetX = (int)((x1 - x0) / def.texelSize.x);
float y0 = def.untrimmedBoundsData[0].y - def.untrimmedBoundsData[1].y / 2;
float y1 = def.boundsData[0].y - def.boundsData[1].y / 2;
regionOffsetY = (int)((y1 - y0) / def.texelSize.y);
material = def.materialInst;
}
示例5: parseDate
/// <summary>
/// Parse a rfc 2822 date and time specification. rfc 2822 section 3.3
/// </summary>
/// <param name="date">rfc 2822 date-time</param>
/// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns>
public static DateTime parseDate( String date )
{
if ( date==null || date.Equals(String.Empty) )
return DateTime.MinValue;
DateTime msgDateTime;
date = SharpMimeTools.SharpMimeTools.uncommentString (date);
msgDateTime = new DateTime (0);
try {
// TODO: Complete the list
date = date.Replace("UT", "+0000");
date = date.Replace("GMT", "+0000");
date = date.Replace("EDT", "-0400");
date = date.Replace("EST", "-0500");
date = date.Replace("CDT", "-0500");
date = date.Replace("MDT", "-0600");
date = date.Replace("MST", "-0600");
date = date.Replace("EST", "-0700");
date = date.Replace("PDT", "-0700");
date = date.Replace("PST", "-0800");
date = date.Replace("AM", String.Empty);
date = date.Replace("PM", String.Empty);
int rpos = date.LastIndexOfAny(new Char[]{' ', '\t'});
if (rpos>0 && rpos != date.Length - 6)
date = date.Substring(0, rpos + 1) + "-0000";
date = date.Insert(date.Length-2, ":");
msgDateTime = DateTime.ParseExact(date,
_date_formats,
CultureInfo.CreateSpecificCulture("en-us"),
DateTimeStyles.AllowInnerWhite);
#if LOG
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error parsing date: [", date, "]"), e);
#else
} catch ( Exception ) {
#endif
msgDateTime = new DateTime (0);
}
return msgDateTime;
}
示例6: loadFile
internal void loadFile(String filename)
{
if (string.IsNullOrEmpty(luaFile))
throw new Exception("No Lua file specified");
if (!System.IO.File.Exists(filename))
throw new Exception("Cannot find file " + filename);
// store the file data
this.theData = System.IO.File.ReadAllBytes(filename);
interp = new Lua();
this.usedSetData = false;
#region register predefined functions & variables
// register the functions
interp.RegisterFunction("read", this, this.GetType().GetMethod("read"));
interp.RegisterFunction("read2", this, this.GetType().GetMethod("read2"));
interp.RegisterFunction("readWORD", this, this.GetType().GetMethod("readWORD"));
interp.RegisterFunction("readlWORD", this, this.GetType().GetMethod("readlWORD"));
interp.RegisterFunction("readDWORD", this, this.GetType().GetMethod("readDWORD"));
interp.RegisterFunction("readlDWORD", this, this.GetType().GetMethod("readlDWORD"));
interp.RegisterFunction("readString", this, this.GetType().GetMethod("readString"));
interp.RegisterFunction("readString2", this, this.GetType().GetMethod("readString2"));
interp.RegisterFunction("stringToInt", this, this.GetType().GetMethod("stringToInt"));
interp.RegisterFunction("setData", this, this.GetType().GetMethod("setData"));
interp.RegisterFunction("setData2", this, this.GetType().GetMethod("setData2"));
interp.RegisterFunction("addData", this, this.GetType().GetMethod("addData"));
interp.RegisterFunction("addData2", this, this.GetType().GetMethod("addData2"));
interp.RegisterFunction("toHexadecimal", this, this.GetType().GetMethod("ToHexadecimal"));
// register the default variables
interp["filesize"] = theData.Length;
interp["filename"] = filename.Substring(filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1);
interp["filepath"] = filename.Substring(0, filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1);
#endregion
// read the plugin
try
{
interp.DoFile(this.luaFile);
// if the variable invalid has been set, display it, and reset the data
if (interp["invalid"] != null)
{
MainWindow.ShowError(interp.GetString("invalid"));
this.bData.Data = new byte[0];
}
else
{
#region format
// try to read the format
if (interp["format"] != null)
{
int format = (int)(double)interp["format"];
switch (this.Parent.BindingType)
{
case BindingType.GRAPHICS:
if (format < 1 || format > 7)
MainWindow.ShowError("Plugin warning: the format of the graphics should range from 1 up to and including 7.\n"
+ "Value " + format + " is ignored");
else
GraphicsData.GraphFormat = (GraphicsFormat)format;
break;
case BindingType.PALETTE:
if (format < 5 || format > 7)
MainWindow.ShowError("Plugin warning: the format of the palette should range from 5 up to and including 7.\n"
+ "Value " + format + " is ignored");
else
PaletteData.PalFormat = (PaletteFormat)format;
break;
}
}
#endregion
if (this.parentBinding.BindingType == BindingType.PALETTE || (int)GraphicsData.GraphFormat >= 5)
{
#region palette order
if (interp["order"] != null)
{
string s = ((string)interp["order"]).ToUpper();
if (s.Length != 3 || !s.Contains("R") || !s.Contains("G") || !s.Contains("B"))
MainWindow.ShowError("Plugin warning: the colour order is invalid.\n"
+ "Value " + s + " is ignored.");
else
PaletteData.PalOrder = (PaletteOrder)Enum.Parse(typeof(PaletteOrder), s);
}
#endregion
#region alpha location
if (interp["alphaAtStart"] != null)
{
bool atStart = (bool)interp["alphaAtStart"];
PaletteData.AlphaSettings.Location = atStart ? AlphaLocation.START : AlphaLocation.END;
}
#endregion
#region ignore alpha
if (interp["ignoreAlpha"] != null)
{
//.........這裏部分代碼省略.........
示例7: Validate
private String Validate(String value)
{
if (value == null || value.Length == 0)
return value;
Char[] validateChar = {(Char)0xD, (Char)0x9};
int index = value.LastIndexOfAny(validateChar);
if (index > -1)
throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:token", value));
if (value.Length > 0)
{
if (Char.IsWhiteSpace(value[0]) || Char.IsWhiteSpace(value[value.Length - 1]))
throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:token", value));
}
index = value.IndexOf(" ");
if (index > -1)
throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:token", value));
return value;
}
示例8: parseDate
/// <summary>
/// Parse a rfc 2822 date and time specification. rfc 2822 section 3.3
/// </summary>
/// <param name="date">rfc 2822 date-time</param>
/// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns>
public static DateTime parseDate(String date)
{
if (date == null || date.Equals(String.Empty))
return DateTime.MinValue;
DateTime msgDateTime = new DateTime(0);
date = anmar.SharpMimeTools.SharpMimeTools.uncommentString(date);
try
{
// TODO: Complete the list
date = date.Replace("UT", "+0000");
date = date.Replace("GMT", "+0000");
date = date.Replace("EDT", "-0400");
date = date.Replace("EST", "-0500");
date = date.Replace("CDT", "-0500");
date = date.Replace("MDT", "-0600");
date = date.Replace("MST", "-0600");
date = date.Replace("EST", "-0700");
date = date.Replace("PDT", "-0700");
date = date.Replace("PST", "-0800");
date = date.Replace("AM", String.Empty);
date = date.Replace("PM", String.Empty);
int rpos = date.LastIndexOfAny(new Char[] { ' ', '\t' });
if (rpos > 0 && rpos != date.Length - 6)
date = date.Substring(0, rpos + 1) + "-0000";
date = date.Insert(date.Length - 2, ":");
msgDateTime = DateTime.ParseExact(date,
_date_formats,
System.Globalization.CultureInfo.CreateSpecificCulture("en-us"),
System.Globalization.DateTimeStyles.AllowInnerWhite);
}
catch (Exception)
{
msgDateTime = new DateTime(0);
}
return msgDateTime;
}
示例9: CheckForSpecialCharHelper
private static void CheckForSpecialCharHelper(String typeName, int endIndex)
{
int originalEnd = endIndex;
char[] specialChars = { ',', '[', ']', '+', '\\' };
while (endIndex >= 0) {
endIndex = typeName.LastIndexOfAny(specialChars, endIndex);
if (endIndex == -1)
return;
bool evenSlashes = true;
if ((typeName[endIndex] == '\\') &&
(endIndex != originalEnd)) {
char nextChar = typeName[endIndex+1];
if ((nextChar == '+') ||
(nextChar == '[') ||
(nextChar == ']') ||
(nextChar == '&') ||
(nextChar == '*') ||
(nextChar == ','))
evenSlashes = false;
}
while ((--endIndex >= 0) &&
typeName[endIndex] == '\\')
evenSlashes = !evenSlashes;
// Even number of slashes means this is a lone special char
if (evenSlashes)
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeName"));
}
}
示例10: PathEnd
internal static String PathEnd(String path)
{
path = path.TrimEnd(anySlash);
int i = path.LastIndexOfAny(anySlash);
if (i >= 0)
path = path.Substring(i + 1);
return path;
}
示例11: strip_path
public static String strip_path(String str)
{
int pos = Math.Max(0, str.LastIndexOfAny(path_sep));
return str.Substring(pos);
}