InfoPath substring-after and substring-before functions

Learn how you can use the substring-after and substring-before functions in InfoPath 2010 to extract a date and time from a datetime string.

The substring-before() and substring-after() functions are two of 10 functions in InfoPath you can use to manipulate strings.

The substring-after() function returns the text in the first text string that follows the first occurrence of the second text string.

The substring-before() function returns the text in the first text string that precedes the first occurrence of the second text string.

You can use the substring-after() and substring-before() functions in formulas in InfoPath. Suppose you have two fields (field1 and field2) on an InfoPath form. If you set the Default Value of field2 to be equal to the formula:

substring-after(field1, "InfoPath")

and you type the text "Hello from InfoPath today" in field1, you should see the text "today" appear in field2, because "today" follows the first occurrence of the text "InfoPath".

Likewise, if you set the Default Value of field2 to be equal to the formula:

substring-before(field1, "InfoPath")

and you type the text "Hello from InfoPath today" in field1, you should see the text "Hello from" appear in field2, because "Hello from" precedes the first occurrence of the text "InfoPath".

Because dates and times are stored as strings in InfoPath, you can use the substring-before() and substring-after() functions with date and time pickers to split the date and string into a date portion and a time portion. Note that if you want to split a date string into a day, month, and year, it is best to use the subtring() function instead.

In the InfoPath video shown below you will learn how you can use the substring-before() and substring-after() functions in InfoPath formulas to extract a date and a time from a string.

In this InfoPath 2010 tutorial video, you learned...

  • How to construct a formula that makes use of the substring-before() function in InfoPath.
  • How to construct a formula that makes use of the substring-after() function in InfoPath.
  • How to use the now() function with the substring-before() and substring-after() functions in InfoPath 2010.

See more InfoPath 2010 tutorial videos »

 


Related InfoPath Articles:

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services