Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.Contains Method (String)

 

Returns a value indicating whether a specified substring occurs within this string.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

member Contains : 
        value:string -> bool

Parameters

value
Type: System.String

The string to seek.

Return Value

Type: System.Boolean

true if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.

Exception Condition
ArgumentNullException

value is null.

This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.

If you are interested in the position of the substring value in the current instance, you can call the IndexOf method to get the starting position of its first occurrence, or you can call the LastIndexOf method to get the starting position of its last occurrence. The example includes a call to the IndexOf(String) method if a substring is found in a string instance.

The following example determines whether the string "fox" is a substring of a familiar quotation. If "fox" is found in the string, it also displays its starting position.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft