本文整理汇总了C#中System.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# System.StartsWith方法的具体用法?C# System.StartsWith怎么用?C# System.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.StartsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleMatch
/// <summary> Match a String against the given pattern, supporting the following simple
/// pattern styles: "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality.
/// </summary>
/// <param name="pattern">the pattern to match against
/// </param>
/// <param name="str">the String to match
/// </param>
/// <returns> whether the String matches the given pattern
/// </returns>
public static bool SimpleMatch(System.String pattern, System.String str)
{
if (ObjectUtils.NullSafeEquals(pattern, str) || "*".Equals(pattern))
{
return true;
}
if (pattern == null || str == null)
{
return false;
}
if (pattern.StartsWith("*") && pattern.EndsWith("*") &&
str.IndexOf(pattern.Substring(1, (pattern.Length - 1) - (1))) != -1)
{
return true;
}
if (pattern.StartsWith("*") && str.EndsWith(pattern.Substring(1, (pattern.Length) - (1))))
{
return true;
}
if (pattern.EndsWith("*") && str.StartsWith(pattern.Substring(0, (pattern.Length - 1) - (0))))
{
return true;
}
return false;
}
示例2: StartsWithUsesSpecifiedEqualityComparerOrDefault
public void StartsWithUsesSpecifiedEqualityComparerOrDefault()
{
var first = new[] {1,2,3};
var second = new[] {4,5,6};
Assert.False(first.StartsWith(second));
Assert.False(first.StartsWith(second, null));
Assert.False(first.StartsWith(second, new EqualityComparerFunc<int>((f, s) => false)));
Assert.True(first.StartsWith(second, new EqualityComparerFunc<int>((f, s) => true)));
}
示例3: Accept
/* (non-Javadoc)
* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
*/
public virtual bool Accept(System.IO.FileInfo dir, System.String name)
{
int i = name.LastIndexOf((System.Char) '.');
if (i != - 1)
{
System.String extension = name.Substring(1 + i);
if (extensions.Contains(extension))
{
return true;
}
else if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
{
return true;
}
else if (extension.StartsWith("s") && (new System.Text.RegularExpressions.Regex("s\\d+")).Match(extension).Success)
{
return true;
}
}
else
{
if (name.Equals(IndexFileNames.DELETABLE))
return true;
else if (name.StartsWith(IndexFileNames.SEGMENTS))
return true;
}
return false;
}
示例4: SetRawValue
/// <summary> Set the value of the attribute and the quote character.
/// If the value is pure whitespace, assign it 'as is' and reset the
/// quote character. If not, check for leading and trailing double or
/// single quotes, and if found use this as the quote character and
/// the inner contents of <code>value</code> as the real value.
/// Otherwise, examine the string to determine if quotes are needed
/// and an appropriate quote character if so. This may involve changing
/// double quotes within the string to character references.
/// </summary>
/// <param name="value">The new value.
/// </param>
public virtual void SetRawValue(System.String value_Renamed)
{
char ch;
bool needed;
bool singleq;
bool doubleq;
System.String ref_Renamed;
System.Text.StringBuilder buffer;
char quote;
quote = (char) (0);
if ((null != value_Renamed) && (0 != value_Renamed.Trim().Length))
{
if (value_Renamed.StartsWith("'") && value_Renamed.EndsWith("'") && (2 <= value_Renamed.Length))
{
quote = '\'';
value_Renamed = value_Renamed.Substring(1, (value_Renamed.Length - 1) - (1));
}
else if (value_Renamed.StartsWith("\"") && value_Renamed.EndsWith("\"") && (2 <= value_Renamed.Length))
{
quote = '"';
value_Renamed = value_Renamed.Substring(1, (value_Renamed.Length - 1) - (1));
}
else
{
// first determine if there's whitespace in the value
// and while we're at it find a suitable quote character
needed = false;
singleq = true;
doubleq = true;
for (int i = 0; i < value_Renamed.Length; i++)
{
ch = value_Renamed[i];
if ('\'' == ch)
{
singleq = false;
needed = true;
}
else if ('"' == ch)
{
doubleq = false;
needed = true;
}
else if (!('-' == ch) && !('.' == ch) && !('_' == ch) && !(':' == ch) && !System.Char.IsLetterOrDigit(ch))
{
needed = true;
}
}
// now apply quoting
if (needed)
{
if (doubleq)
quote = '"';
else if (singleq)
quote = '\'';
else
{
// uh-oh, we need to convert some quotes into character
// references, so convert all double quotes into "
quote = '"';
ref_Renamed = """; // Translate.encode (quote);
// JDK 1.4: value = value.replaceAll ("\"", ref);
buffer = new System.Text.StringBuilder(value_Renamed.Length * (ref_Renamed.Length - 1));
for (int i = 0; i < value_Renamed.Length; i++)
{
ch = value_Renamed[i];
if (quote == ch)
buffer.Append(ref_Renamed);
else
buffer.Append(ch);
}
value_Renamed = buffer.ToString();
}
}
}
}
SetValue(value_Renamed);
SetQuote(quote);
}
示例5: getEncoding
/// <summary> Returns a String representing the encoding of the given message, if
/// the encoding is recognized. For example if the given message appears
/// to be encoded using HL7 2.x XML rules then "XML" would be returned.
/// If the encoding is not recognized then null is returned. That this
/// method returns a specific encoding does not guarantee that the
/// message is correctly encoded (e.g. well formed XML) - just that
/// it is not encoded using any other encoding than the one returned.
/// </summary>
public override System.String getEncoding(System.String message)
{
System.String encoding = null;
//quit if the string is too short
if (message.Length < 4)
return null;
//see if it looks like this message is | encoded ...
bool ok = true;
//string should start with "MSH"
if (!message.StartsWith("MSH"))
return null;
//4th character of each segment should be field delimiter
char fourthChar = message[3];
SupportClass.Tokenizer st = new SupportClass.Tokenizer(message, System.Convert.ToString(segDelim), false);
while (st.HasMoreTokens())
{
System.String x = st.NextToken();
if (x.Length > 0)
{
if (System.Char.IsWhiteSpace(x[0]))
x = stripLeadingWhitespace(x);
if (x.Length >= 4 && x[3] != fourthChar)
return null;
}
}
//should be at least 11 field delimiters (because MSH-12 is required)
int nextFieldDelimLoc = 0;
for (int i = 0; i < 11; i++)
{
nextFieldDelimLoc = message.IndexOf((System.Char) fourthChar, nextFieldDelimLoc + 1);
if (nextFieldDelimLoc < 0)
return null;
}
if (ok)
encoding = "VB";
return encoding;
}
示例6: matches
public virtual bool matches(int lineNumber, System.String line)
{
if (line.StartsWith("_cell_length_a") || line.StartsWith("_audit_creation_date") || line.StartsWith("loop_"))
{
return true;
}
return false;
}
示例7: GenerationFromSegmentsFileName
/// <summary> Parse the generation off the segments file name and
/// return it.
/// </summary>
public static long GenerationFromSegmentsFileName(System.String fileName)
{
if (fileName.Equals(IndexFileNames.SEGMENTS))
{
return 0;
}
else if (fileName.StartsWith(IndexFileNames.SEGMENTS))
{
return SupportClass.Number.ToInt64(fileName.Substring(1 + IndexFileNames.SEGMENTS.Length));
}
else
{
throw new System.ArgumentException("fileName \"" + fileName + "\" is not a segments file");
}
}
示例8: matches
public virtual bool matches(int lineNumber, System.String line)
{
if (lineNumber == 1 && line.StartsWith("frame: "))
{
return true;
}
return false;
}
示例9: GetWildcardQuery
/// <summary> Factory method for generating a query. Called when parser
/// parses an input term token that contains one or more wildcard
/// characters (? and *), but is not a prefix term token (one
/// that has just a single * character at the end)
/// <p/>
/// Depending on settings, prefix term may be lower-cased
/// automatically. It will not go through the default Analyzer,
/// however, since normal Analyzers are unlikely to work properly
/// with wildcard templates.
/// <p/>
/// Can be overridden by extending classes, to provide custom handling for
/// wildcard queries, which may be necessary due to missing analyzer calls.
///
/// </summary>
/// <param name="field">Name of the field query will use.
/// </param>
/// <param name="termStr">Term token that contains one or more wild card
/// characters (? or *), but is not simple prefix term
///
/// </param>
/// <returns> Resulting {@link Query} built for the term
/// </returns>
/// <exception cref="ParseException">throw in overridden method to disallow
/// </exception>
public /*protected internal*/ virtual Query GetWildcardQuery(System.String field, System.String termStr)
{
if ("*".Equals(field))
{
if ("*".Equals(termStr))
return NewMatchAllDocsQuery();
}
if (!allowLeadingWildcard && (termStr.StartsWith("*") || termStr.StartsWith("?")))
throw new ParseException("'*' or '?' not allowed as first character in WildcardQuery");
if (lowercaseExpandedTerms)
{
termStr = termStr.ToLower();
}
Term t = new Term(field, termStr);
return NewWildcardQuery(t);
}
示例10: Search
/// <summary>
/// Action: Search
/// </summary>
/// <param name="ContainerID">Associated State Variable: A_ARG_TYPE_ObjectID</param>
/// <param name="SearchCriteria">Associated State Variable: A_ARG_TYPE_SearchCriteria</param>
/// <param name="Filter">Associated State Variable: A_ARG_TYPE_Filter</param>
/// <param name="StartingIndex">Associated State Variable: A_ARG_TYPE_Index</param>
/// <param name="RequestedCount">Associated State Variable: A_ARG_TYPE_Count</param>
/// <param name="SortCriteria">Associated State Variable: A_ARG_TYPE_SortCriteria</param>
/// <param name="Result">Associated State Variable: A_ARG_TYPE_Result</param>
/// <param name="NumberReturned">Associated State Variable: A_ARG_TYPE_Count</param>
/// <param name="TotalMatches">Associated State Variable: A_ARG_TYPE_Count</param>
/// <param name="UpdateID">Associated State Variable: A_ARG_TYPE_UpdateID</param>
public void Search(System.String ContainerID, System.String SearchCriteria, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, out System.String Result, out System.UInt32 NumberReturned, out System.UInt32 TotalMatches, out System.UInt32 UpdateID)
{
// Action: Search
// This action allows the caller to search the content directory for objects that match
// some search criteria. The search criteria are specified as a query string operating on
// properties with comparison and logical operators.
Result = String.Empty;
NumberReturned = 0;
TotalMatches = 0;
UpdateID = 0;
//http://code.google.com/p/jems/wiki/XBox360Notes
//4 audioItem
//5 musicGenre
//6 musicArtist
//7 musicAlbum
//F playlistContainer
//14 folders
if (ContainerID.StartsWith("0") == true ||
ContainerID.StartsWith("4") == true ||
ContainerID.StartsWith("5") == true ||
ContainerID.StartsWith("6") == true ||
ContainerID.StartsWith("7") == true ||
ContainerID.StartsWith("F") == true ||
ContainerID.StartsWith("14") == true)
{
StringBuilder sb = new StringBuilder();
sb.Append(DidlHandler.BeginDidl());
NumberReturned = 0;
TotalMatches = 0;
//if (SearchCriteria.IndexOf("upnp:class derivedfrom \"object.item.imageItem\"", StringComparison.InvariantCultureIgnoreCase) == -1 &&
// SearchCriteria.IndexOf("upnp:class derivedfrom \"object.item.videoItem\"", StringComparison.InvariantCultureIgnoreCase) == -1)
if (SearchCriteria.IndexOf("upnp:class derivedfrom \"object.item.audioItem\"", StringComparison.InvariantCultureIgnoreCase) >= 0)
{
// Always JUMP to 4 !
ContainerID = "4";
if (ContainerID == "0")
{
//NumberReturned = 1;
TotalMatches = 1;
sb.AppendLine(DidlHandler.GetContainer("14", "0", "Music", "object.container.storageFolder"));
//Result = "<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\">" +
// "<container id=\"14\" parentID=\"\" childCount=\"0\"><dc:title>Live Stream</dc:title><upnp:class>object.container.storageFolder</upnp:class></container>" +
// //"<container id=\"15\" parentID=\"\" childCount=\"0\"><dc:title>Videos</dc:title><upnp:class>object.container.storageFolder</upnp:class></container>" +
// //"<container id=\"16\" parentID=\"\" childCount=\"0\"><dc:title>Pictures</dc:title><upnp:class>object.container.storageFolder</upnp:class></container>" +
// "</DIDL-Lite>";
}
else if (ContainerID == "4" || ContainerID == "5" || ContainerID == "6" || ContainerID == "7" || ContainerID == "14") //return all songs
{
sb.Append(this.GetMp3StreamItem());
sb.Append(this.GetL16StreamItem());
TotalMatches = 2;
}
}
//TODO respect # requested from client
NumberReturned = TotalMatches;
sb.Append(DidlHandler.EndDidl());
Result = sb.ToString();
}
}
示例11: IsAllowed
/// <summary> Returns <code>false</code> if the <code>robots.txt</code> file
/// prohibits us from accessing the given <code>path</code>, or
/// <code>true</code> otherwise.
/// </summary>
public virtual bool IsAllowed(System.String path)
{
try
{
path = HttpUtility.UrlDecode(path, System.Text.Encoding.GetEncoding(RobotRulesParser.CHARACTER_ENCODING.ToLower()));
}
catch (System.Exception e)
{
// just ignore it- we can still try to match
// path prefixes
}
if (m_entries == null)
{
m_entries = new RobotsEntry[m_tmpEntries.Count];
m_entries = (RobotsEntry[]) Support.ICollectionSupport.ToArray(m_tmpEntries, m_entries);
m_tmpEntries = null;
}
int pos = 0;
int end = m_entries.Length;
while (pos < end)
{
if (path.StartsWith(m_entries[pos].m_strPrefix))
return m_entries[pos].m_bAllowed;
pos++;
}
return true;
}
示例12: matches
public virtual bool matches(int lineNumber, System.String line)
{
if (line.StartsWith("!Header gpr"))
{
return true;
}
return false;
}
示例13: Message
public override void Message(System.String message)
{
if (message.StartsWith("now flush at close") && 0 == thrown.Count)
{
thrown.Add(null);
throw new System.OutOfMemoryException("fake OOME at " + message);
}
}
示例14: ToFriendlyTypeNameShouldReturnProperNameWhenTypeIsAnonymousWithGeneric
public void ToFriendlyTypeNameShouldReturnProperNameWhenTypeIsAnonymousWithGeneric()
{
var name = new { Int = 1, String = "Test" }.GetType().ToFriendlyTypeName();
Assert.True(name.StartsWith("AnonymousType"));
Assert.True(name.EndsWith("<Int32, String>"));
}
示例15: ToFriendlyTypeNameShouldReturnProperNameWhenTypeIsAnonymous
public void ToFriendlyTypeNameShouldReturnProperNameWhenTypeIsAnonymous()
{
var name = new { }.GetType().ToFriendlyTypeName();
Assert.True(name.StartsWith("AnonymousType"));
}