ParseValueFromConcatenatedString ( )

Function stats

Average user rating
281
301
9999
Support
FileMaker 7.0 +
Date posted
12 April 2011
Last updated
12 April 2011
Version
Recursive function
No

Author Info
 Marcelo Piñeyro

3 functions

Average Rating None

author_avatar



 

Function overview

Prototype

ParseValueFromConcatenatedString  ( string;   separator;   valueNumber )


Parameters

string  


separator  


valueNumber  


Description

Tags:  Text Parsing  

Use this function to extract a given value from a string of concatenated values. You can either specify a number representing the position of the value that you are interested in in the list of concatenated values, or you can use the terms "first" or "last" to return the first or last values. The separator is also specified as a parameter in the custom function and can be any string of text. A separator is necessary only between values; a separator at the beginning or end of the string is not necessary.

Examples

Sample input

ParseValueFromConcatenatedString( "value1|value2|value3" ; "|" ; 2 )


Sample output

"value2" (without the quotation marks)

 

Function code

/*
Name:
ParseValueFromConcatenatedString

History:
Created by Marcelo Piñeyro, Wingra Consulting LLC, marcelo@wingraconsulting.com
Date created: February 2011
Date modified: February 2011

Purpose:
To extract a single value from a string of values concatenated using a separator of the user's choosing.

Parameters:
string: text string of values separated by a given separator.
separator: any text string, typically a single character such as the pipe symbol |.
valueNumber: a number representing the value in the concatenated list of values. In addition to numbers, this parameter accepts the terms "first" and "last".

Dependencies:
No dependencies.

Example:
ParseValueFromConcatenatedString( "value1|value2|value3" ; "|" ; 2 ) returns "value2" (without the quotation marks)

Other Notes:
A separator is necessary only between values; a separator at the beginning or end of the string is not necessary.
*/

Let(
[
    values = Substitute( string ; separator ; ¶ ) ;
    valueCount = ValueCount( values )
] ;

Case(

valueNumber = "first" ; GetValue( values ; 1 ) ;

valueNumber = "last" ; GetValue( values ; valueCount ) ;

GetValue( values ; valueNumber )

)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/301

    Prototype: ParseValueFromConcatenatedString( string; separator; valueNumber )
    Function Author: Marcelo Piñeyro (http://www.fmfunctions.com/mid/281)
    Last updated: 12 April 2011
    Version: 1.1

*/
// ===================================

 

Comments

Fabrice
12 April 2011



A reason why I would use a pipe (|) or anything as a separator rather than a carriage return (¶) would be to be able to work with multi-lines texts. I'm afraid the use of GetValue is not taking benefit of this.
I don't like quoting myself, but did you try BetweenNext? (published on this very site)
  General comment
Marcelo Piñeyro
18 April 2011



This function is intended to easily extract a single value from a single text string. I often pass multiple parameters into a script in the form "id|value|etc", and I use this custom function in the script to quickly extract each value and set a variable for each value.
  General comment
Fabrice
18 April 2011



Well, I understood this. But what about a multi-line piece of data? An address for example.
Using text parsing functions (position, left...) instead of GetValue, you could handle these.
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (31)
Date  (26)
List  (26)
Format  (23)
XML  (22)
Sql  (18)
Dev  (18)
Debug  (15)
Interface  (13)
Text  (13)
Layout  (12)
Variables  (12)
Design  (10)
Filter  (10)
Layout Objects  (8)
Timestamp  (7)