本文整理汇总了C#中String.TrimEnd方法的典型用法代码示例。如果您正苦于以下问题:C# String.TrimEnd方法的具体用法?C# String.TrimEnd怎么用?C# String.TrimEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.TrimEnd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillAttributeInfo
// Returns 0 on success, otherwise a Win32 error code. Note that
// classes should use -1 as the uninitialized state for dataInitialized.
internal static int FillAttributeInfo(String path, ref Win32Native.WIN32_FILE_ATTRIBUTE_DATA data, bool tryagain, bool returnErrorOnNotFound)
{
int dataInitialised = 0;
if (tryagain) // someone has a handle to the file open, or other error
{
Win32Native.WIN32_FIND_DATA findData;
findData = new Win32Native.WIN32_FIND_DATA ();
// Remove trialing slash since this can cause grief to FindFirstFile. You will get an invalid argument error
String tempPath = path.TrimEnd(new char [] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar});
// For floppy drives, normally the OS will pop up a dialog saying
// there is no disk in drive A:, please insert one. We don't want that.
// SetErrorMode will let us disable this, but we should set the error
// mode back, since this may have wide-ranging effects.
int oldMode = Win32Native.SetErrorMode(Win32Native.SEM_FAILCRITICALERRORS);
try {
bool error = false;
SafeFindHandle handle = Win32Native.FindFirstFile(tempPath,findData);
try {
if (handle.IsInvalid) {
error = true;
dataInitialised = Marshal.GetLastWin32Error();
if (dataInitialised == Win32Native.ERROR_FILE_NOT_FOUND ||
dataInitialised == Win32Native.ERROR_PATH_NOT_FOUND ||
dataInitialised == Win32Native.ERROR_NOT_READY) // floppy device not ready
{
if (!returnErrorOnNotFound) {
// Return default value for backward compatibility
dataInitialised = 0;
data.fileAttributes = -1;
}
}
return dataInitialised;
}
}
finally {
// Close the Win32 handle
try {
handle.Close();
}
catch {
// if we're already returning an error, don't throw another one.
if (!error) {
Debug.Assert(false, "File::FillAttributeInfo - FindClose failed!");
__Error.WinIOError();
}
}
}
}
finally {
Win32Native.SetErrorMode(oldMode);
}
// Copy the information to data
data.PopulateFrom(findData);
}
else
{
// For floppy drives, normally the OS will pop up a dialog saying
// there is no disk in drive A:, please insert one. We don't want that.
// SetErrorMode will let us disable this, but we should set the error
// mode back, since this may have wide-ranging effects.
bool success = false;
int oldMode = Win32Native.SetErrorMode(Win32Native.SEM_FAILCRITICALERRORS);
try {
success = Win32Native.GetFileAttributesEx(path, GetFileExInfoStandard, ref data);
}
finally {
Win32Native.SetErrorMode(oldMode);
}
if (!success) {
dataInitialised = Marshal.GetLastWin32Error();
if (dataInitialised != Win32Native.ERROR_FILE_NOT_FOUND &&
dataInitialised != Win32Native.ERROR_PATH_NOT_FOUND &&
dataInitialised != Win32Native.ERROR_NOT_READY) // floppy device not ready
{
// In case someone latched onto the file. Take the perf hit only for failure
return FillAttributeInfo(path, ref data, true, returnErrorOnNotFound);
}
else {
if (!returnErrorOnNotFound) {
// Return default value for backward compbatibility
dataInitialised = 0;
data.fileAttributes = -1;
}
}
}
}
return dataInitialised;
}
示例2: FillAttributeInfo
[System.Security.SecurityCritical] // auto-generated
internal static int FillAttributeInfo(String path, ref Interop.mincore.WIN32_FILE_ATTRIBUTE_DATA data, bool tryagain, bool returnErrorOnNotFound)
{
int errorCode = 0;
if (tryagain) // someone has a handle to the file open, or other error
{
Interop.mincore.WIN32_FIND_DATA findData;
findData = new Interop.mincore.WIN32_FIND_DATA();
// Remove trialing slash since this can cause grief to FindFirstFile. You will get an invalid argument error
String tempPath = path.TrimEnd(PathHelpers.DirectorySeparatorChars);
// For floppy drives, normally the OS will pop up a dialog saying
// there is no disk in drive A:, please insert one. We don't want that.
// SetErrorMode will let us disable this, but we should set the error
// mode back, since this may have wide-ranging effects.
uint oldMode = Interop.mincore.SetErrorMode(Interop.mincore.SEM_FAILCRITICALERRORS);
try
{
bool error = false;
SafeFindHandle handle = Interop.mincore.FindFirstFile(tempPath, ref findData);
try
{
if (handle.IsInvalid)
{
error = true;
errorCode = Marshal.GetLastWin32Error();
if (errorCode == Interop.mincore.Errors.ERROR_FILE_NOT_FOUND ||
errorCode == Interop.mincore.Errors.ERROR_PATH_NOT_FOUND ||
errorCode == Interop.mincore.Errors.ERROR_NOT_READY) // floppy device not ready
{
if (!returnErrorOnNotFound)
{
// Return default value for backward compatibility
errorCode = 0;
data.fileAttributes = -1;
}
}
return errorCode;
}
}
finally
{
// Close the Win32 handle
try
{
handle.Dispose();
}
catch
{
// if we're already returning an error, don't throw another one.
if (!error)
{
throw Win32Marshal.GetExceptionForLastWin32Error();
}
}
}
}
finally
{
Interop.mincore.SetErrorMode(oldMode);
}
// Copy the information to data
data.PopulateFrom(findData);
}
else
{
// For floppy drives, normally the OS will pop up a dialog saying
// there is no disk in drive A:, please insert one. We don't want that.
// SetErrorMode will let us disable this, but we should set the error
// mode back, since this may have wide-ranging effects.
bool success = false;
uint oldMode = Interop.mincore.SetErrorMode(Interop.mincore.SEM_FAILCRITICALERRORS);
try
{
success = Interop.mincore.GetFileAttributesEx(path, Interop.mincore.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref data);
}
finally
{
Interop.mincore.SetErrorMode(oldMode);
}
if (!success)
{
errorCode = Marshal.GetLastWin32Error();
if (errorCode != Interop.mincore.Errors.ERROR_FILE_NOT_FOUND &&
errorCode != Interop.mincore.Errors.ERROR_PATH_NOT_FOUND &&
errorCode != Interop.mincore.Errors.ERROR_NOT_READY) // floppy device not ready
{
// In case someone latched onto the file. Take the perf hit only for failure
return FillAttributeInfo(path, ref data, true, returnErrorOnNotFound);
}
else
{
if (!returnErrorOnNotFound)
{
// Return default value for backward compatibility
errorCode = 0;
//.........这里部分代码省略.........
示例3: ParseExact
// Parse a DateTime value, using exact format information.
public static DateTime ParseExact(String s, String[] formats,
IFormatProvider provider,
DateTimeStyles style)
{
DateTimeFormatInfo info;
int posn;
// Validate the parameters.
if(s == null)
{
throw new ArgumentNullException("s");
}
if(formats == null)
{
throw new ArgumentNullException("formats");
}
for(posn = 0; posn < formats.Length; ++posn)
{
if(formats[posn] == null)
{
throw new ArgumentNullException
("formats[" + posn.ToString() + "]");
}
else if(formats[posn] == String.Empty)
{
throw new FormatException(_("Format_Empty"));
}
}
// Get the date time format information from the provider.
info = DateTimeFormatInfo.GetInstance(provider);
// Strip white space from the incoming string.
if((style & DateTimeStyles.AllowLeadingWhite) != 0)
{
s = s.TrimStart(null);
}
if((style & DateTimeStyles.AllowTrailingWhite) != 0)
{
s = s.TrimEnd(null);
}
if(s == String.Empty)
{
throw new FormatException
(_("ArgRange_StringNonEmpty"));
}
// Process each of the formats in turn. We may need
// to recursively re-enter ParseExact if single-letter
// format characters are used within the list.
for(posn = 0; posn < formats.Length; ++posn)
{
try
{
if(formats[posn].Length == 1)
{
return ParseExact
(s, info.GetAllDateTimePatterns
(formats[posn][0]), info, style);
}
else
{
return TryParse
(s, formats[posn], info, style);
}
}
catch(FormatException)
{
// Didn't match this format. Try the next one.
}
}
// If we get here, then we were unable to parse the string.
throw new FormatException(_("Format_DateTime"));
}