Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 7 of 7

Thread: Find delimiter

  1. #1
    Join Date
    Feb 2004
    Posts
    131

    Cool Find delimiter

    Is there a way to read a text file and identify the delimiter without the need to specify the delimiter type in the code or by the user?

    Example...

    The first text file reads:

    John Doe;;123 Riverside Drive;;Beverly Hills;;CA;;90210;;etc...

    The second text file reads:

    John Doe|123 Riverside Drive|Beverly Hills|CA|90210|etc...

    the output should find the delimiter type used in each text file
    "The delimiter found is ;;"
    "The delimiter found is |"

    I tried using string.find and searching for different types of patterns but it seemed be code overkill.

    Thanks

  2. #2
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    What if you just start the file with ||John Doe or ;;John Doe so you can determine it like this:

    Code:
    sTextfile = TextFile.ReadToString("textfile.txt");
    sDelimiter = String.Mid(sTextfile, 1, 2);
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  3. #3
    Join Date
    Feb 2004
    Posts
    131
    The transactions are prepared by hundreds of different users, each using there own accounting software, and using various delimiters.

    I must gather the info from each file (thousands) in an attempt to organize the data.

    The delimiter is usually shown after the first entry like this:
    Credit card|$34.99 |$43.24 |$3.30 |$4.95

    In some cases, the delimiter is random like, "---", making it difficult to search commonly used delimiters.

  4. #4
    Join Date
    May 2006
    Posts
    5,380
    How i would do it,

    Code:
    function GetDelimiter(sDelimitedString, tbDelimiters)
    
    	local sRet=""
    
    	for index, sDelimiter in tbDelimiters do
    		if String.ReverseFind(sDelimitedString, sDelimiter, false) ~= -1 then
    			sRet=sDelimiter;
    			break;
    		end
    	end
    		
    	return sRet
    end
    
    -- Test
    Dialog.Message("Test", "The delimiter for this string is '"..GetDelimiter("Item1|Item2|Item3|Item4|Item", {"|",",",";","/"}).."'");
    Dialog.Message("Test", "The delimiter for this string is '"..GetDelimiter("Item1,Item2,Item3,Item4,Item", {"|",",",";","/"}).."'");
    Dialog.Message("Test", "The delimiter for this string is '"..GetDelimiter("Item1;Item2;Item3;Item4;Item", {"|",",",";","/"}).."'");
    Dialog.Message("Test", "The delimiter for this string is '"..GetDelimiter("Item1/Item2/Item3/Item4/Item", {"|",",",";","/"}).."'");
    In some cases, the delimiter is random like, "---", making it difficult to search commonly used delimiters.
    the only thing i can suggest for that is as each new delimiter is encounterd add it to the tbDelimiters table.
    Last edited by RizlaUK; 11-01-2008 at 10:54 AM.
    Open your eyes to Narcissism, Don't let her destroy your life!!

  5. #5
    Join Date
    Jun 2008
    Posts
    108
    I you know that the symbol $ is given in front of the amount, you can parse for the symols between number and the $ symbol.

    Normaly there should be a standard how the data in the accounting software has to be formed.

  6. #6
    Join Date
    Feb 2004
    Posts
    131

    Thumbs up

    This works very well R, thank you. I still have to specify the delimiter, but I don't think there is any way around that. I added a few extra delimiters I have encountered so far.

    -- Locate the data file
    Data_file = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "All Files (*.txt)|*.txt|", "", "", false, false);
    Data_file = TextFile.ReadToString(Data_file[1]);

    function GetDelimiter(sDelimitedString, tbDelimiters)

    local sRet=""

    for index, sDelimiter in tbDelimiters do
    if String.ReverseFind(sDelimitedString, sDelimiter, false) ~= -1 then
    sRet=sDelimiter;
    break;
    end
    end

    return sRet
    end

    sTab = String.Char(9);
    sData = GetDelimiter(Data_file, {"|",",",";","/",sTab,":",";;","::","||","---","--"});

    -- convert to a comma delimited data file
    output = String.Replace(Data_file, sData, ",", true);
    Dialog.Message("test", output, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    Last edited by Stephen G.; 11-01-2008 at 12:22 PM.

  7. #7
    Join Date
    Feb 2004
    Posts
    131
    This is a reply to P. The entries do not all have the "$" symbol in front.
    I believe R's code works well, so long as the delimiter is not uncommon.

    Thanx
    Last edited by Stephen G.; 11-01-2008 at 12:25 PM.

Similar Threads

  1. Example File Find across multiple Drives
    By Eagle in forum Setup Factory 7.0
    Replies: 7
    Last Post: 11-11-2008, 04:49 AM
  2. Can't Find Thread I'm Looking For..
    By coderanger in forum AutoPlay Media Studio 6.0
    Replies: 3
    Last Post: 02-21-2007, 04:36 PM
  3. Changing Driveletters - how to find the correct one ?
    By C-zar in forum AutoPlay Media Studio 5.0
    Replies: 10
    Last Post: 11-12-2004, 06:17 AM
  4. How would I find a blank line of text via "Find Text Line"?
    By Marker0077 in forum Setup Factory 6.0
    Replies: 11
    Last Post: 07-11-2003, 08:55 AM
  5. Replies: 2
    Last Post: 01-13-2003, 01:00 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