User Tag List

Results 1 to 5 of 5

Thread: Extract number from line in file

  1. #1
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2015
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extract number from line in file

    I have a text file where every line is "number:word", so it looks something like this:

    15:banana
    64:cherry
    1235:apple
    192387:grape
    238:avocado

    What I want to do is extract the number associated with a given word. For example if Word was "apple", I would want to get the number 1235.
    So far, I'm loading the text into a Rich Edit Object and using "Find string in string" to find where the given word starts:

    Find(GetText$( "Edit Object", 0, GetNChars( "Edit Object" ) ), Word, 0)

    Then I'm trying to extract the number by getting the characters that appear before the chosen word (minus the colon). I'm having trouble with this because the numbers vary in length so I can't say exactly how many characters to get. Can anyone think of a better way to do this?

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    SoftWarewolf's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    941
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    How about this way? tokenized.mfa
    I used the String Tokenizer object.

  3. #3
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2015
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks SoftWarewolf. I eventually figured out an expression using a bunch of Right$, Left$, Len, Find etc commands but your way is much simpler!

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,366
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it is important not to over-complicate stuff
    Splitting text with a delimiter is common in all programming languages, and in Fusion you can do it using the String Tokenizer or String Parser 2. String Tokenizer is often the best one and even has a 2D split feature, which would be useful in your case.
    I haven't seen SoftWarewolf's example because I can't open files that uses Unicode extensions, so he might have used this same technique. You would 2D split the text with newline$ as the X delimiter, and ":" as the Y delimiter. Then you would loop through all the X items and retrieve each Y item in each.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    SoftWarewolf's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    941
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    That's spot on what it does

Similar Threads

  1. Testing for Number of Objects in a Line
    By Corlen in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 22nd January 2012, 03:33 AM
  2. Are there any MMF2 objects which can decompress/extract CAB file contents?
    By RGBreality in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 5th December 2011, 01:25 AM
  3. Number of objects on a line
    By Banshee in forum Multimedia Fusion 2 - Technical Support
    Replies: 23
    Last Post: 27th January 2008, 04:05 PM
  4. Suggestions: Undo, Line around object, Number
    By Tiles in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 4th August 2006, 04:50 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
  •