Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 6 of 6

Thread: String.Find

  1. #1
    Join Date
    Jan 2002
    Location
    Nashville TN
    Posts
    328

    String.Find

    Any ideas for how to get a count of the number of substrings in a string.

    Maybe a String.FindCount function?

    I have a files with "_" as a field seporator (Example: "BAJANGO_ARONNAX_4654474_PTRE_20070117.pdf") but clients can add additional fields so the given number of "_" can change don’t want to recode this part every time, a String.FindCount that returns a count of a repeated substrings. So one can create a loop.

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Use the DelimitedStringToTable with "_" as the delimiter, then get the table count.

    Code:
    Arguments:	DelimitedString - The string to parse
    			Delimiter - The delimiter
    Returns: A numerically indexed table with the string elements
    Example:
    
    string = "Brett,Mark,Darryl,Lorne,Adam";
    tbResults = DelimitedStringToTable(string,",");
    for i, name in tbResults do
    	Dialog.Message("Name",name);
    end
    
    ]]--
    function DelimitedStringToTable(DelimitedString, Delimiter)
    	tbReturn = {};
    	local strWorking;
    	local nPos = nil;
    	local strData;
    	local nTableIndex = 1;
    	local nDelimiterLength = String.Length(Delimiter);
    	
    	if(nDelimiterLength < 1)then
    		tbReturn[nTableIndex] = DelimitedString;
    		return tbReturn;
    	end
    	
    	strWorking = DelimitedString;
    	nPos = String.Find(strWorking,Delimiter);
    	while(nPos ~= -1)do
    		strData = String.Left(strWorking,nPos-1);
    		tbReturn[nTableIndex] = strData;
    		nTableIndex = nTableIndex + 1;
    		local nLength = String.Length(strWorking);
    		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
    		nPos = String.Find(strWorking,Delimiter);
    	end
    	if(strWorking ~= "")then
    		tbReturn[nTableIndex] = strWorking;
    	end
    	
    	return tbReturn;
    end

  3. #3
    Join Date
    Jan 2002
    Location
    Nashville TN
    Posts
    328
    Nice work man, I am going to give this a try but looking at the code I think you have it nailed.

  4. #4
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    I can't take credit for the function, that's an IR goodie that comes in the Scriplets of AMS. Not sure if its in SF7 or not. Anyhow, hope you're good to go.

  5. #5
    Join Date
    Jan 2002
    Location
    Nashville TN
    Posts
    328
    Yes I already have it working (just a few customization and one minor modification), You saved me from having to recreate it myself. Scriplets you say I will have to look see, I am AMS5/6 as well as SF7.

  6. #6
    Join Date
    Jun 2005
    Posts
    470
    another one, probably faster, if not - at least shorter

    Code:
    function subStrCount(strInp, strPattern)
      return (String.Length(strInp)- String.Length(String.Replace(strInp,strPattern,"",true))) / String.Length(strPattern);
    end
    replace true with false for case insensitive search, or make it a parameter

Similar Threads

  1. Example: Using LUA's string.find & Character Ranges
    By Intrigued in forum AutoPlay Media Studio 7.5 Examples
    Replies: 5
    Last Post: 05-06-2007, 07:05 AM
  2. list of words for String.find ..?
    By TristanD in forum AutoPlay Media Studio 6.0
    Replies: 4
    Last Post: 01-20-2007, 01:51 PM
  3. String.Find help needed
    By Jerryab in forum AutoPlay Media Studio 6.0
    Replies: 6
    Last Post: 05-02-2006, 10:24 PM
  4. Character Ranges - string.find - string - find
    By Intrigued in forum AutoPlay Media Studio 6.0
    Replies: 0
    Last Post: 11-07-2005, 06:48 PM
  5. Example: Using String.Find to Locate a Substring
    By Corey in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 11-02-2004, 12:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts