{"id":441,"date":"2014-02-12T22:06:03","date_gmt":"2014-02-12T22:06:03","guid":{"rendered":"http:\/\/www.lorenzcom.com\/?p=441"},"modified":"2020-12-03T07:25:36","modified_gmt":"2020-12-03T13:25:36","slug":"getvalueindexbyposition","status":"publish","type":"post","link":"https:\/\/lorenzcom.com\/?p=441","title":{"rendered":"GetValueIndexByPosition"},"content":{"rendered":"<h3>GetValueIndexByPosition ( valueList , valueString , matchCase , occurrence , positionLCR )<\/h3>\n<p>GetValueIndexByPosition retrieves the index of the value in a value list whose left, center or right portion matches the value string search text. Returns 0 if not found. Toggle case-sensitive searching by passing a boolean through matchCase. Search for specific valueString occurrence &#8211; a negative occurrence number causes backward search from the end of the valueList. Specify whether to match the valueString from the Left, Center (middle), or Right within the value.<\/p>\n<h4>Parameters<\/h4>\n<ul>\n<li>valueList &#8211; Value list to search.<\/li>\n<li>valueString &#8211; Text to search for in valueList.<\/li>\n<li>matchCase &#8211; Require search to find exact case-sensitive match only.<\/li>\n<li>occurrence &#8211; Specify which instance of the valueString in valueList to search for and retrieve. A negative number cause a backward search from end of valueList.<\/li>\n<li>positionLCR &#8211; Specify where in each value to search for the valueString text: left side, center, or right side.<\/li>\n<\/ul>\n<h4>Examples<\/h4>\n<ul>\n<li>GetValueIndexByPosition ( &#8220;Alpha\u00b6Bravo\u00b6Charlie\u00b6Echo&#8221;, &#8220;charl&#8221;, False, 1, &#8220;L&#8221; ) = 3<\/li>\n<li>GetValueIndexByPosition ( &#8220;Alpha\u00b6Bravo\u00b6Charlie\u00b6Echo&#8221;, &#8220;charlie&#8221;, True, 1, &#8220;L&#8221; ) = 0<\/li>\n<li>GetValueIndexByPosition ( &#8220;Daniel\u00b6Danny\u00b6Bill\u00b6daniel\u00b6Frank\u00b6daniel\u00b6Ed&#8221;, &#8220;aniel&#8221;, True, -2, &#8220;R&#8221; ) = 4<\/li>\n<li>GetValueIndexByPosition ( &#8220;Daniel\u00b6Danny\u00b6Bill\u00b6daniel\u00b6Frank\u00b6daniel\u00b6Ed&#8221;, &#8220;an&#8221;, False, -2, &#8220;C&#8221; ) = 5<\/li>\n<\/ul>\n<p><strong>NOTICE:<\/strong> This function is a recursive function. If you change the name of it, then change the name references inside the code.<\/p>\n<p><strong>GetValueIndexByPOsition code:<\/strong> Copy the selected code (click on Select All to highlight all the code) to the clipboard and paste it into a newly created Custom Function. <a href=\"\/docs\/FileMaker\/GetValueIndexByPosition.zip\">Download the code in a text file from here.<\/a><\/p>\n<form><textarea id=\"&lt;?php\"> style=&#8221;width:100%; height:180px; font-family:Arial,Helvetica; font-size:.90em; line-height:normal;&#8221;&gt;&lt;!&#8211;raw&#8211;&gt;Let ( [ vtext = Substitute ( valueString ; &#8220;\u00b6&#8221; ; &#8220;&#8221; ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Set from where in each value to search ( the justification of the valueString in each valueList value ) &#8211; L[eft], C[enter], R[ight].&lt;br \/&gt;<br \/>\njust = If ( IsEmpty ( positionLCR ) ; &#8220;L&#8221; ; Left ( positionLCR ; 1 ) ) ; &lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Set vlist and vtext ( the search string ) based on justification: L, R, C.&lt;br \/&gt;<br \/>\nvlist = Case ( just = &#8220;L&#8221; ; &#8220;\u00b6&#8221; &amp; valueList ; just = &#8220;R&#8221; ; valueList &amp; &#8220;\u00b6&#8221; ; valueList ) ;&lt;br \/&gt;<br \/>\nvtext = Case ( just = &#8220;L&#8221; ; &#8220;\u00b6&#8221; &amp; vtext ; just = &#8220;R&#8221; ; vtext &amp; &#8220;\u00b6&#8221; ; vtext ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Get position of vtext in vlist. Continue searching until pos is 0.&lt;br \/&gt;<br \/>\npos = If ( occurrence = 0 ; 0 ; Position ( vlist ; vtext ; If ( occurrence &lt; 0 ; Length ( vlist ) ; 1 ) ; If ( occurrence &lt; 0 ; -1 ; 1 ) ) ) ;<\/p>\n<p>\/\/Get index of found valueString in valueList.<br \/>\nindex = If ( pos ; PatternCount ( Left ( vlist ; pos &#8211; 1 ) ; &#8220;\u00b6&#8221; ) ; 0 ) ;<\/p>\n<p>\/\/Always test if search string is exact match to the text found at pos, for use in occurrance adjustment statement.<br \/>\nmatch = Exact ( Middle ( vlist ; pos ; Length ( vtext ) ) ; vtext ) ;<\/p>\n<p>\/\/Adjust occurrence toward 0. If pos = 0 then set to 0. If matchCase then adjust only if matched, else adjust all.<br \/>\noccurrence = Case ( pos = 0 ; 0 ; matchCase ; If ( match ; occurrence + If ( occurrence &gt; 0 ; -1 ; 1 ) ; occurrence ) ; occurrence + If ( occurrence &gt; 0 ; -1 ; 1 ) ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Prepare for recursive call. Get remaining valueList to search.&lt;br \/&gt;<br \/>\nvlist = Case ( occurrence &lt; 0 ; Left ( valueList ; pos &#8211; 1 ) ; occurrence &gt; 0 ; Right ( valueList ; Length ( valueList ) &#8211; ( ( pos &#8211; 1 ) + Length ( valueString ) ) ) ; &#8220;&#8221; ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Recursive call only if not done. Store returned index.&lt;br \/&gt;<br \/>\nindex2 = If ( occurrence \u2260 0 ; GetValueIndexByPosition ( vlist ; valueString ; matchCase ; occurrence ; just ) ; 0 ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Set value to return. Add to previous index or send most recent index.&lt;br \/&gt;<br \/>\nindex = Case ( occurrence &lt; 0 ; index2 ; occurrence &gt; 0 ; If ( index2 = 0 ; 0 ; index + index2 ) ; index ) + If ( occurrence = 0 and ( index &gt; 0 or ( index = 0 and pos &gt; 0 ) ) ; 1 ; 0 ) ] ;&lt;\/p&gt;<br \/>\n&lt;p&gt;index&lt;\/p&gt;<br \/>\n&lt;p&gt;)&lt;\/p&gt;<br \/>\n&lt;p&gt;\/*&lt;br \/&gt;<br \/>\nGetValueIndexByPosition ( valueList, valueString, matchCase, occurrence, positionLCR ) &lt;\/p&gt;<br \/>\n&lt;p&gt;by Lewis C. Lorenz.&lt;\/p&gt;<br \/>\n&lt;p&gt;8\/19\/2016: UPDATED. &lt;\/p&gt;<br \/>\n&lt;p&gt;Retrieve the index of the value in valueList containing the matching valueString. Returns 0 if not found.&lt;br \/&gt;<br \/>\nToggle case-sensitive searching by passing a boolean through matchCase.&lt;br \/&gt;<br \/>\nSearch for specific valueString occurrence. A negative occurrence number causes backward search from the end of the valueList.&lt;br \/&gt;<br \/>\nSpecify whether to match the valueString from the Left, Center ( middle ) , or Right within the value.&lt;\/p&gt;<br \/>\n&lt;p&gt;NOTICE: This is a recursive function. If you change the function name then also change it in the function code.&lt;\/p&gt;<br \/>\n&lt;p&gt;Examples:&lt;br \/&gt;<br \/>\nGetValueIndexByPosition ( &#8220;Alpha\u00b6Bravo\u00b6Charlie\u00b6Echo&#8221;, &#8220;charl&#8221;, False, 1, &#8220;L&#8221; ) = 3&lt;br \/&gt;<br \/>\nGetValueIndexByPosition ( &#8220;Alpha\u00b6Bravo\u00b6Charlie\u00b6Echo&#8221;, &#8220;charlie&#8221;, True, 1, &#8220;L&#8221; ) = 0&lt;br \/&gt;<br \/>\nGetValueIndexByPosition ( &#8220;Daniel\u00b6Danny\u00b6Bill\u00b6daniel\u00b6Frank\u00b6daniel\u00b6Ed&#8221;, &#8220;aniel&#8221;, True, -2, &#8220;R&#8221; ) = 4&lt;br \/&gt;<br \/>\nGetValueIndexByPosition ( &#8220;Daniel\u00b6Danny\u00b6Bill\u00b6daniel\u00b6Frank\u00b6daniel\u00b6Ed&#8221;, &#8220;an&#8221;, False, -2, &#8220;C&#8221; ) = 5&lt;br \/&gt;<br \/>\n*\/&lt;!&#8211;\/raw&#8211;&gt;<\/textarea><br \/>\n<input form=\"\" type=\"text\" \/> type=&#8221;button&#8221; value=&#8221;Select All&#8221; \/&gt; <input type=\"reset\" value=\"Reset\" \/><\/form>\n","protected":false},"excerpt":{"rendered":"<p>GetValueIndexByPosition ( valueList , valueString , matchCase , occurrence , positionLCR ) GetValueIndexByPosition retrieves the index of the value in a value list whose left, center or right portion matches the value string search text. Returns 0 if not found. <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/lorenzcom.com\/?p=441\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,14,34],"tags":[],"_links":{"self":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/441"}],"collection":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=441"}],"version-history":[{"count":20,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/441\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/441\/revisions\/873"}],"wp:attachment":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}