Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2006
    Posts
    16

    How do I search for the end of a numeric string?

    Hiya, I'm trying to retrieve a string from a html file and in a very clumsy way have almost achieved what I want to do. However I'm stumped about how to sort the retrieved data. I need to clean up the numerical value after the "clientid=". The clientid field could have characters from 1 to n and is always followed by a character like " ' ; etc. How can I check through the numerical string until I reach the end number before the ;' " etc and then store the value?

    I think the best way to do this would be to search initially for the string "clientid=" and then search for the variable numerical data following it ie 7875. I don't think using string.mid is the best way of doing this

    I assume I would use a while loop and if the string was clientid=7875"; the program would check 7 then 8 then 7 etc until it finds the " and then will store only the numerical value as a new string. I'm struggling with this as I am new to programming and string manipulation but I really want to learn.

    Here's what I have so far:

    result = TextFile.ReadToString("C:\\htmlsource.txt");
    clientid = String.Find(result, "clientid", 1, false);
    clientid1 = String.Mid(result, clientid, 10);
    Thankyou for taking the time to help me.

    All the best Rob

  2. #2
    Join Date
    Nov 2003
    Location
    Myrtle Beach, SC
    Posts
    155

    Try This

    Here's a generic function that will do what you're wanting. (This is similar to the way that I extract snippets from Web pages.)

    Code:
    function read_token_value_from_file (filepath, token)
    -- returns "-1" if file does not exist
    -- returns "" if the token or number does not exist
    -- otherwise returns the clientid as a string
    -- (use String.ToNumber on the result, if needed)
    	
    	-- init default
    	local out_str = "-1";
    
    	-- read the file
    	if (File.DoesExist(filepath)) then
    		result = TextFile.ReadToString(filepath);
    	else
    		return (out_str);
    	end
    	
    	-- find it
    	local nPos = String.Find(result, token);
    	out_str = ""; -- reset default
    	if (nPos > 0) then
    		-- extract text starting with the number
    		local temp_str = String.Left(result, nPos + String.Length(token) - 1);
    		temp_str = String.Replace(result, temp_str, "");
    		-- now, get the number
    		local counter = 1;
    		local asc = String.Asc(String.Mid(temp_str, counter, 1));
    		while ((asc >= 48) and (asc <= 57)) do
    			out_str = out_str .. String.Char(asc);
    			counter = counter + 1;
    			asc = String.Asc(String.Mid(temp_str, counter, 1));
    		end
    	end
    	result = "";
    	return (out_str);
    end
    
    -- test it...
    this_clientID_str = read_token_value_from_file("AutoPlay\\Docs\\htmlsource.txt", "clientid=");
    Dialog.Message("test this", this_clientID_str);
    Last edited by CyberRBT; 03-26-2007 at 04:55 AM.

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. how to search for string over the whole project
    By Dimon in forum AutoPlay Media Studio 6.0
    Replies: 6
    Last Post: 03-22-2006, 04:49 PM
  3. help with ftp connect
    By CAI in forum AutoPlay Media Studio 6.0
    Replies: 0
    Last Post: 09-29-2005, 07:13 PM
  4. Another tough one... Interaction between Web and AMS
    By Agent Jones in forum AutoPlay Media Studio 5.0
    Replies: 13
    Last Post: 08-18-2005, 02:10 PM

Posting Permissions

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