本文整理汇总了C#中System.String.TrimEnd方法的典型用法代码示例。如果您正苦于以下问题:C# String.TrimEnd方法的具体用法?C# String.TrimEnd怎么用?C# String.TrimEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.TrimEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertStringToMilliseconds
/// <summary>
///
/// </summary>
/// <param name="myString">String </param>
/// <returns>The value in milliseconds</returns>
public static Int32 ConvertStringToMilliseconds(String myString)
{
// Guard Block
// String null
// String ""
// String " "
if (String.IsNullOrWhiteSpace(myString))
{
throw new ArgumentException("Value was null, empty, or not a recognized time format.");
}
// Try Parse in the hopes that they gave us a number without ANY suffix
int num;
bool res = int.TryParse(myString, out num);
if (res)
{
// Log statement saying that we're good
}
// Hours suffix scenario - h
else if (myString.EndsWith("h"))
{
myString = myString.TrimEnd(new char[] {'h'});
bool x = int.TryParse(myString, out num);
if (x)
{
num = num * 3600000;
}
}
// Minute suffix scenario - m
else if (myString.EndsWith("m"))
{
myString = myString.TrimEnd(new char[] { 'm' });
bool x = int.TryParse(myString, out num);
if (x)
{
num = num * 60000;
}
}
// Second suffix scenario - s
else if (myString.EndsWith("s"))
{
myString = myString.TrimEnd(new char[] { 's' });
bool x = int.TryParse(myString, out num);
if (x)
{
num = num * 1000;
}
}
else
{
throw new ArgumentException("Value is not a recognized time format.");
}
return num;
}
示例2: I4ch
/// <summary>
/// Converts 4-byte integer array into character string.
/// </summary>
/// <param name="ibuf">Integer array to convert</param>
/// <param name="nbyte">The number of bytes to convert (expected to be
/// a multiple of 4)</param>
/// <returns></returns>
internal static string I4ch(int* ibuf, int nbyte)
{
Debug.Assert((nbyte%4) == 0);
char[] res = new char[nbyte];
for (int i=0, j=0; i<nbyte/4; i++, j+=4)
{
int val = ibuf[i];
#if (_SUN)
res[j+3] = (char)(val & 0x000000FF);
res[j+2] = (char)((val & 0x0000FF00) >> 8);
res[j+1] = (char)((val & 0x00FF0000) >> 16);
res[j] = (char)((val & 0xFF000000) >> 24);
#else
res[j] = (char)(val & 0x000000FF);
res[j+1] = (char)((val & 0x0000FF00) >> 8);
res[j+2] = (char)((val & 0x00FF0000) >> 16);
res[j+3] = (char)((val & 0xFF000000) >> 24);
#endif
}
// Force any embedded nulls into blanks.
for (int i=0; i<nbyte; i++)
{
if (res[i]=='\0')
res[i] = ' ';
}
// Strip off trailing white space
string s = new String(res);
return s.TrimEnd(null);
}
示例3: findAppDocOfModule
private XmlElement findAppDocOfModule(String pDir, String pIOCode) {
XmlElement vRslt = null;
String vAppCfgFN = pDir + "app.config";
if(File.Exists(vAppCfgFN)) {
XmlDocument vDoc = dom4cs.OpenDocument(vAppCfgFN).XmlDoc;
XmlNodeList vMods = vDoc.DocumentElement.SelectNodes("load/module[not(@enabled) or (@enabled='true')]");
foreach(XmlElement vMod in vMods) {
//if((!vMod.HasAttribute("enabled") || String.Equals(vMod.GetAttribute("enabled"), "true", StringComparison.CurrentCultureIgnoreCase))
// && String.Equals(vMod.GetAttribute("iocode"), pIOCode, StringComparison.CurrentCultureIgnoreCase)) {
if(String.Equals(vMod.GetAttribute("iocode"), pIOCode, StringComparison.CurrentCultureIgnoreCase)) {
vRslt = vMod;
break;
}
}
}
if((vRslt == null) && !String.IsNullOrEmpty(pDir)) {
DirectoryInfo vCurDir = new DirectoryInfo(pDir);
DirectoryInfo vPrntDir = Directory.GetParent(pDir.TrimEnd(new Char[]{'\\'}));
if ((vPrntDir != null) && (vPrntDir.FullName.ToLower().StartsWith(this.BioSession.Cfg.LocalPath.ToLower()))) {
String vNextIOCode = vCurDir.Name + "." + pIOCode;
vRslt = this.findAppDocOfModule(vPrntDir.FullName + "\\", vNextIOCode);
}
}
return vRslt;
}
示例4: InternalTrimTrailingSeparator
/// <summary>
/// Removes spaces end <see cref="DirectorySeparatorChar "/> at the end of a string
/// </summary>
internal static String InternalTrimTrailingSeparator( String path )
{
Contract.Requires( !String.IsNullOrWhiteSpace( path ) );
Contract.Ensures( !String.IsNullOrWhiteSpace( Contract.Result<String>() ) );
return path.TrimEnd( WhiteSpace ).TrimEnd( DirectorySeparatorChar );
}
示例5: JsonToDictionary
public Dictionary<string, string> JsonToDictionary(String input, String firstCol)
{
//if(input.IndexOf("{"
//input = input.Replace('\"','');
/*
input = input.Substring(input.IndexOf("{" + firstCol) + 1);
input = input.Substring(0, input.IndexOf("}"));
*/
/*
while (input.IndexOf('\\') >= 0)
{
int index = input.IndexOf('\\');
input = input.Substring(0, index) + input.Substring(index + 1);
}
*/
input = input.Substring(1);
input = input.Substring(0,input.Length-1);
while (input.IndexOf('\"') >= 0)
{
int index = input.IndexOf('\"');
input = input.Substring(0, index) + input.Substring(index + 1);
}
/*
input.Replace(':', '=');
input.Replace(',', ';');
*/
return input.TrimEnd(',').Split(',').ToDictionary(item => item.Split(':')[0], item => item.Split(':')[1]);
}
示例6: ServerConnectionModel
public ServerConnectionModel(String hostIP, String userName, String userPassword)
{
Host = hostIP;
User = userName;
Password = userPassword;
Host.TrimEnd('/');
}
示例7: SectionEntry
public uint Offset; //the offset of this section in the nxz
public SectionEntry(Stream stream)
{
BinaryReader rdr = new BinaryReader(stream);
Name = new String(rdr.ReadChars(rdr.ReadByte()));
Name = Name.TrimEnd('\0');//dont include the required terminator
type = (Types)rdr.ReadByte();
Length = rdr.ReadUInt32();
u3 = rdr.ReadInt32();
}
示例8: RegisterNamespaceMapping
/// <summary>
/// Map C# (server) class namespace to JS (client) namespace. Use * and % to define prefix mappings.
/// </summary>
/// <param name="ns">Name of the C# (server) namespace. If the name ends with *, prefix match is used. If the name ends with % only that part of namespace is mapped. </param>
/// <param name="cns">Name of the JS (client) namespace.</param>
public void RegisterNamespaceMapping(String ns, String cns)
{
namespaceMapping.Add(new NamespaceMapping
{
Namespace = ns.TrimEnd('*'),
ClientNamespace = (cns ?? "").TrimEnd('*'),
Mode = GetNamespaceMappingMode(ns, cns)
});
}
示例9: StringToByteArray
//hex轉byte用的
public static byte[] StringToByteArray(String hex)
{
hex = hex.TrimEnd('\r', '\n');//trim CRLF
int NumberChars = hex.Length;
byte[] bytes = new byte[NumberChars / 2];
for (int i = 0; i < NumberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
示例10: CopyToContainerAsync
public async Task CopyToContainerAsync(
IAsyncCommandContext context,
String source,
CancellationToken cancellationToken)
{
//set maxConcurrentUploads up to 2 untill figure out how to use WinHttpHandler.MaxConnectionsPerServer modify DefaultConnectionLimit
int maxConcurrentUploads = Math.Min(Environment.ProcessorCount, 2);
//context.Output($"Max Concurrent Uploads {maxConcurrentUploads}");
IEnumerable<String> files;
if (File.Exists(source))
{
files = new List<String>() { source };
_sourceParentDirectory = Path.GetDirectoryName(source);
}
else
{
files = Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories);
_sourceParentDirectory = source.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}
context.Output(StringUtil.Loc("TotalUploadFiles", files.Count()));
foreach (var file in files)
{
_fileUploadQueue.Enqueue(file);
}
using (_uploadCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
{
List<Task> allRunningTasks = new List<Task>();
// start reporting task to keep tracking upload progress.
allRunningTasks.Add(ReportingAsync(context, files.Count(), _uploadCancellationTokenSource.Token));
// start parallel upload task.
for (int i = 0; i < maxConcurrentUploads; i++)
{
allRunningTasks.Add(ParallelUploadAsync(context, i, _uploadCancellationTokenSource.Token));
}
// the only expected type of exception will throw from both parallel upload task and reporting task is OperationCancelledException.
try
{
await Task.WhenAll(allRunningTasks);
}
catch (OperationCanceledException)
{
// throw aggregate exception for all non-operationcancelexception we catched during file upload.
if (_exceptionsDuringFileUpload.Count > 0)
{
throw new AggregateException(_exceptionsDuringFileUpload).Flatten();
}
throw;
}
}
}
示例11: OwnerData
/// <summary>
/// Создает экземпляр класса
/// </summary>
/// <param name="address">Адрес</param>
/// <param name="id">Код</param>
/// <param name="inn">ИНН</param>
/// <param name="kpp">КПП</param>
/// <param name="name">Наименование</param>
/// <param name="section">Номер секции ФР</param>
/// <param name="warrant">Номер свидетельства ИП</param>
public OwnerData(String id, String name, String address, String inn, String kpp,
String warrant, Int32 section)
{
_id = id.TrimEnd();
_name = name.TrimEnd();
_address = address.TrimEnd();
_inn = inn.TrimEnd();
_kpp = kpp.TrimEnd();
_warrant = warrant.TrimEnd();
_section = section;
}
示例12: Combine
/// <summary>
/// Combines several path elements
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static String Combine(String left, String right)
{
// remove delimiter
right = right.TrimStart(Delimiter);
left = left.TrimEnd(Delimiter);
// build the path
if (right.Length == 0)
return left;
else
return left + Delimiter + right;
}
示例13: fromJSON
public Dictionary<String, String> fromJSON(String json)
{
Dictionary<String, String> dict = new Dictionary<String, String>();
Char[] splits = new Char[1];
splits[0] = ',';
if (!String.IsNullOrEmpty(json))
{
json = json.Trim();
// Remove leading and trailing breakets
if (json.StartsWith("{"))
{
json = json.Remove(0, 1);
json = json.TrimStart();
}
if (json.EndsWith("}"))
{
json = json.Remove(json.Length - 1);
json = json.TrimEnd();
}
String[] jsonItems = json.Split(splits, StringSplitOptions.RemoveEmptyEntries);
// iterate all comma-separeted key-value-pairs
for (int i = 0; i < jsonItems.Length; i++)
{
String currentPart = jsonItems[i];
// check if it's a 'real' item-separator or maybe a comma inside a 'marked' string
if (checkForConsistentQuotes(currentPart) && currentPart.Contains(":"))
{
processKeyValuePair(dict, currentPart);
}
// we splitted inside a string, so do some error-handling
else if (i < jsonItems.Length - 1)
{
// add upcoming parts as long as we do not have a 'working' part
do
{
i++;
currentPart += "," + jsonItems[i];
}
while (!(checkForConsistentQuotes(currentPart) && currentPart.Contains(":")));
processKeyValuePair(dict, currentPart);
}
}
}
return dict;
}
示例14: PathCombine
public String PathCombine(String path1, String path2) {
path1 = path1.TrimEnd("/\\".ToCharArray());
path2 = path2.TrimStart("/\\".ToCharArray());
if(Environment.OSVersion.Platform == PlatformID.Win32NT) {
path1 = path1.Replace("/","\\");
path2 = path2.Replace("/","\\");
}
if(string.IsNullOrWhiteSpace(path1) || string.IsNullOrEmpty(path1))
return path2;
else
return String.Format("{0}{1}{2}",path1,Path.DirectorySeparatorChar,path2);
}
示例15: GetBytes
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
var str = new String(chars);
str = str.Replace(" ", "");
for(int i = charIndex ; i < charIndex + str.Length ; i += 2)
{
var charOffset = i - charIndex;
var byteString = new String(new char[] { str[i], str[i + 1] });
var b = byte.Parse(byteString.TrimEnd(), NumberStyles.HexNumber);
bytes[byteIndex + charOffset / 2] = b;
}
return str.Length / 2;
}