string - Delphi - Using Functions in CASE statements -


in delphi 10 / seattle, trying nested string test...i have string, product name. need find product category based on product name. case insensitive, , each product in 1 category. once find category, can stop checking...my initial approach via ansicontainstext within case statement, not allowed since there no common function case statement...

i have approach should work, there little more elegant? have 40 different tests category, , running (looping through) test on 6000 products, want performant possible.

      // determine new value...       category := '';       if ((category = '') , (ansicontainstext(producttext, 'paas'))  category := 'paas';       if ((category = '') , (ansicontainstext(producttext, 'iaas'))  category := 'iaas';       if ((category = '') , (ansicontainstext(producttext, 'saas'))  category := 'saas'; ... 

outsource it!

function findcategory(const productname: string): string; const   categories: tarray<string> = ['paas', 'iaas', 'saas']; // can extended var   s: string; begin   s in categories begin     if containstext(productname, s) exit(s)   end;   result := ''; end; 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -