How to declare the Contains function in XML using XQuery

In this article we will discuss about how to contains function in XQuery.
  • 3627

This is one of the most important function of the XQuery which checks whether the string contains a particular character or not. It returns the Boolean value means if the particular strings contains the particular character given by the user this function returns the true value otherwise false value. this function works on String type value.

The syntax of declaring Contains function is as follows:

  fn:contains ($arg1 as xs:string? , $arg2 as xs:string?) as xs:boolean?

Here fn is the prefix to the contains method and this function takes two argument , the first argument is for the name of the string to test and the second argument is for the substring to test for. here xs:boolean indicates the return type of this function.

Here is example of this function to be cleared with this.
 
 XQuery Contains function example   Output
contains('God is great', 'e')  true
contains('God is great', 'od')  true
contains('God is great', 'great')  true
contains('God is great', 'm')  false
contains('God is great', ' ')  true
contains('God is great', ( ))  true
contains('God is great', 'h')  false

Ask Your Question

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.