本文整理汇总了C#中System.String.IndexOfAny方法的典型用法代码示例。如果您正苦于以下问题:C# String.IndexOfAny方法的具体用法?C# String.IndexOfAny怎么用?C# String.IndexOfAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.IndexOfAny方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsValidMappingName
/// <summary>
/// Check if we may use that name - we allow only names like "layout_my_XYZ"
/// </summary>
/// <param name="mapName">A map name</param>
/// <returns>True if valid</returns>
public static Boolean IsValidMappingName( String mapName )
{
Boolean retVal = true; // for now
retVal &= mapName.StartsWith( c_UserMapStartsWith );
retVal &= ( mapName.IndexOfAny( new char[] { ' ', '\t', '\n', '\r', '\0' } ) < 0 ); // make sure we don't have spaces etc.
return retVal;
}
示例2: nanoPubSubClient
public nanoPubSubClient(String clientId)
{
if(clientId.IndexOfAny(new char[] { '#' }) != -1)
{
throw new Exception("invalid character '#' in client ID");
}
this.clientId = clientId;
}
示例3: Write
public void Write(String s) {
if (x != 0) wr.Write("" + Sep);
if (s.IndexOfAny(new char[] { Sep, Quote, '\r', '\n' }) < 0) {
wr.Write(s);
}
else {
wr.Write(Quote + s.Replace("" + Quote, "" + Quote + Quote) + Quote);
}
x++;
}
示例4: IsValidFilename
/// <summary>
/// Определяет, является ли указанное название файла валидным
/// </summary>
/// <param name="Input"></param>
/// <returns></returns>
public static Boolean IsValidFilename(String Input)
{
if (Input.HasVisibleChars() == false) { return false; }
if (Input.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { return false; }
if (Input.Length > MAX_FILENAME) { return false; }
if (Input.EndsWith(" ", StringComparison.InvariantCultureIgnoreCase) == true) { return false; }
String part = Input.Trim().Split(new char[1] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
if (part.IsIn(StringComparison.OrdinalIgnoreCase, FilePathTools.IllegalFilenames) == true) { return false; }
return true;
}
示例5: DirectoryInfo
// Constructor.
public DirectoryInfo(String path)
{
if(path == null)
{
throw new ArgumentNullException("path");
}
else if(path.IndexOfAny(Path.InvalidPathChars) != -1)
{
throw new ArgumentException
(_("IO_InvalidPathname"), "path");
}
OriginalPath = path;
FullPath = Path.GetFullPath(path);
}
示例6: a
private static String a(String arg)
{
// for function calls just return it.
if (arg != null && arg.IndexOfAny("()".ToCharArray()) != -1)
{
return arg;
}
// for numbers.
int i;
if (arg != null && int.TryParse(arg, out i))
{
return arg;
}
// strings
return arg == null ? "nil" : "\""+arg+"\"";
}
示例7: IsValidFilePath
/// <summary>
/// Определяет, является ли указанный путь валидным. Поддерживает абсолютные и относительные пути, с названиями файлов и без, а также названия файлов без путей
/// </summary>
/// <param name="Input"></param>
/// <returns></returns>
public static Boolean IsValidFilePath(String Input)
{
if (Input.HasVisibleChars() == false) { return false; }
if (Input.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { return false; }
if(Input.Length >= MAX_PATH) {return false; }
String[] parts = Input.Split(new char[1] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
for (Int32 i = 0; i < parts.Length - 1; i++)
{
String current = parts[i];
if (i < parts.Length - 1)
{
if(current.Length >= MAX_DIRECTORYNAME) {return false; }
}
if (current.HasVisibleChars() == false) { return false; }
String first_part = current.Trim().Split(new char[1] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0];
if (first_part.Trim().IsIn(StringComparison.OrdinalIgnoreCase, IllegalFilenames) == true) { return false; }
}
return FilePathTools.IsValidFilename(parts[parts.Length - 1]);
}
示例8: GetProjektViaNumericProjektID
public Projekt GetProjektViaNumericProjektID(String NumericProjektID)
{
if (NumericProjektID.IndexOfAny(DataSet.AllNumerics) == -1)
return null;
if (NumericProjektID.Length > 6)
{
NumericProjektID = NumericProjektID.Substring(0, 6);
}
else
{
String WordUpStartYear = DataSet.WordUpNameID.Substring(6, 2) + "0000";
NumericProjektID = WordUpStartYear.Substring(0, 6 - NumericProjektID.Length)
+ NumericProjektID;
}
string SelectStatement =
$"Select * from {NativeName} where {NumericProjektIdCol} = '{NumericProjektID}'";
Projekt[] Result = DownloadRows(SelectStatement);
if (Result.Length != 1)
return null;
return Result[0];
}
示例9: ExecuteCommand
public static void ExecuteCommand(String command, PSHost host)
{
Console.WriteLine("Executing command:");
string outputLine = command;
int ichNewline = command.IndexOfAny("\r\n".ToCharArray());
if (ichNewline > 0)
outputLine = command.Substring(0, ichNewline);
Console.WriteLine(outputLine);
using (Runspace space = RunspaceFactory.CreateRunspace(host))
{
space.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = space;
ps.AddScript(command);
// Create the output buffer for the results.
PSDataCollection<PSObject> output = new PSDataCollection<PSObject>();
IAsyncResult async = ps.BeginInvoke();
foreach (PSObject result in ps.EndInvoke(async))
{
Console.WriteLine(result.ToString());
}
PSDataStreams streams = ps.Streams;
if (streams.Error != null)
{
foreach (ErrorRecord record in streams.Error)
{
Console.WriteLine(GetMessageFromErrorRecord(record));
throw record.Exception;
}
}
}
}
}
示例10: ExecuteCommand
public static PSDataCollection<PSObject> ExecuteCommand(String command)
{
Console.WriteLine("Executing command:");
string outputLine = command;
int ichNewline = command.IndexOfAny("\r\n".ToCharArray());
if (ichNewline > 0)
outputLine = command.Substring(0, ichNewline);
Console.WriteLine(outputLine);
using (PowerShell ps = PowerShell.Create())
{
ps.AddScript(command);
IAsyncResult async = ps.BeginInvoke();
PSDataCollection<PSObject> output = ps.EndInvoke(async);
foreach (PSObject result in output)
{
Console.WriteLine(result.ToString());
}
return output;
}
}
示例11: punycode_encode
/*** Main encode function ***/
/* punycode_encode() converts Unicode to Punycode. The input */
/* is represented as an array of Unicode code points (not code */
/* units; surrogate pairs are not allowed), and the output */
/* will be represented as an array of ASCII code points. The */
/* output string is *not* null-terminated; it will contain */
/* zeros if and only if the input contains zeros. (Of course */
/* the caller can leave room for a terminator and add one if */
/* needed.) The input_length is the number of code points in */
/* the input. The output_length is an in/out argument: the */
/* caller passes in the maximum number of code points that it */
/* can receive, and on successful return it will contain the */
/* number of code points actually output. The case_flags array */
/* holds input_length boolean values, where nonzero suggests that */
/* the corresponding Unicode character be forced to uppercase */
/* after being decoded (if possible), and zero suggests that */
/* it be forced to lowercase (if possible). ASCII code points */
/* are encoded literally, except that ASCII letters are forced */
/* to uppercase or lowercase according to the corresponding */
/* uppercase flags. If case_flags is a null pointer then ASCII */
/* letters are left as they are, and other code points are */
/* treated as if their uppercase flags were zero. The return */
/* value can be any of the punycode_status values defined above */
/* except punycode_bad_input; if not punycode_success, then */
/* output_size and output might contain garbage. */
static String punycode_encode(String unicode)
{
// 0 length strings aren't allowed
if (unicode.Length == 0)
throw new ArgumentException(Environment.GetResourceString(
"Argument_IdnBadLabelSize"), "unicode");
Contract.EndContractBlock();
StringBuilder output = new StringBuilder(unicode.Length);
int iNextDot = 0;
int iAfterLastDot = 0;
int iOutputAfterLastDot = 0;
// Find the next dot
while (iNextDot < unicode.Length)
{
// Find end of this segment
iNextDot = unicode.IndexOfAny(M_Dots, iAfterLastDot);
Contract.Assert(iNextDot <= unicode.Length, "[IdnMapping.punycode_encode]IndexOfAny is broken");
if (iNextDot < 0)
iNextDot = unicode.Length;
// Only allowed to have empty . section at end (www.microsoft.com.)
if (iNextDot == iAfterLastDot)
{
// Only allowed to have empty sections as trailing .
if (iNextDot != unicode.Length)
throw new ArgumentException(Environment.GetResourceString(
"Argument_IdnBadLabelSize"), "unicode");
// Last dot, stop
break;
}
// We'll need an Ace prefix
output.Append(M_strAcePrefix);
// Everything resets every segment.
bool bRightToLeft = false;
// Check for RTL. If right-to-left, then 1st & last chars must be RTL
BidiCategory eBidi = CharUnicodeInfo.GetBidiCategory(unicode, iAfterLastDot);
if (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic)
{
// It has to be right to left.
bRightToLeft = true;
// Check last char
int iTest = iNextDot - 1;
if (Char.IsLowSurrogate(unicode, iTest))
{
iTest--;
}
eBidi = CharUnicodeInfo.GetBidiCategory(unicode, iTest);
if (eBidi != BidiCategory.RightToLeft && eBidi != BidiCategory.RightToLeftArabic)
{
// Oops, last wasn't RTL, last should be RTL if first is RTL
throw new ArgumentException(Environment.GetResourceString(
"Argument_IdnBadBidi"), "unicode");
}
}
// Handle the basic code points
int basicCount;
int numProcessed = 0; // Num code points that have been processed so far (this segment)
for (basicCount = iAfterLastDot; basicCount < iNextDot; basicCount++)
{
// Can't be lonely surrogate because it would've thrown in normalization
Contract.Assert(Char.IsLowSurrogate(unicode, basicCount) == false,
"[IdnMapping.punycode_encode]Unexpected low surrogate");
// Double check our bidi rules
//.........这里部分代码省略.........
示例12: GetDisplayName
/// <summary>获取显示名,如果描述不存在,则使用名称,否则使用描述前面部分,句号(中英文皆可)、换行分隔</summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <returns></returns>
public virtual String GetDisplayName(String name, String description)
{
if (String.IsNullOrEmpty(description)) return name;
name = description.Trim();
var p = name.IndexOfAny(new Char[] { '.', '。', '\r', '\n' });
// p=0表示符号在第一位,不考虑
if (p > 0) name = name.Substring(0, p).Trim();
name = name.Replace("$", null);
name = name.Replace("(", null);
name = name.Replace(")", null);
name = name.Replace("(", null);
name = name.Replace(")", null);
name = name.Replace(" ", null);
name = name.Replace(" ", null);
name = name.Replace("/", "_");
name = name.Replace("\\", "_");
if (name[0] == '_') name = name.Substring(1);
return name;
}
示例13: Escape
public static String Escape(String str)
{
// Optimize for nothing to escape (all parameters are run through this function!)
int pos = str.IndexOfAny(new char[] { '=', '&' });
if (pos != -1)
{
// Escape the string
int len = str.Length;
char[] charArray = str.ToCharArray();
StringBuilder sb = new StringBuilder(str.Length + 10); // A random guess at max number of escaped chars
for (int i = 0; i < str.Length; ++i)
{
if (charArray[i] == '=')
sb.Append("=");
else if (charArray[i] == '&')
sb.Append("&");
sb.Append(charArray[i]);
}
return sb.ToString();
}
else
return str;
}
示例14: Escape
public static String Escape( String str )
{
if (str == null)
return null;
StringBuilder sb = null;
int strLen = str.Length;
int index; // Pointer into the string that indicates the location of the current '&' character
int newIndex = 0; // Pointer into the string that indicates the start index of the "remaining" string (that still needs to be processed).
do
{
index = str.IndexOfAny( s_escapeChars, newIndex );
if (index == -1)
{
if (sb == null)
return str;
else
{
sb.Append( str, newIndex, strLen - newIndex );
return sb.ToString();
}
}
else
{
if (sb == null)
sb = new StringBuilder();
sb.Append( str, newIndex, index - newIndex );
sb.Append( GetEscapeSequence( str[index] ) );
newIndex = ( index + 1 );
}
}
while (true);
// no normal exit is possible
}
示例15: IsValidAttributeValue
public static bool IsValidAttributeValue( String value )
{
if (value == null)
return false;
return value.IndexOfAny( s_valueIllegalCharacters ) == -1;
}