Poll: Which is better?

+ Reply to Thread
Results 1 to 4 of 4

Style Question about extracting data from a string?

  1. #1
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Style Question about extracting data from a string?

    This is really only seeking an opinion.

    I have two ways of getting the data I want ( being whatever is to the left of the first space ).
    Please Login or Register  to view this content.
    OR
    Please Login or Register  to view this content.
    These both will return exactly what I need. Tho, the first way will give me an error if there is no " " in the string.
    In the current data that I'm working with, there will always be a " " in the data and no leading space.

    Here's another example, showing why I like 'Split...()(#)' more.
    Imagine a line of text from a router config that has an ip address, that looks like: " ip address 192.168.0.25 255.255.255"

    So:
    Please Login or Register  to view this content.
    Alternatively, I could have used the array completely:
    Please Login or Register  to view this content.
    Beyond that, I could further Split(sIP,".") to get the IP pieces.

    Which do you think is better (And why)?
    Last edited by Rhudi; 02-01-2017 at 09:59 AM. Reason: Typos and elaboration

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Style Question about extranting data from a string?

    Rhudi, split will return an array containing all the elements separated by a " ", so you can turn "a b c" into 3 items in a one dimensional array. While the Left function can only be used to get the "a". If all you want is the item before the space then left is more efficient in terms of memory I suppose, but if you want all 3 (or 2, or more) items then you'd want split. Since it sounds like you only want the first part, left is better for you in this case. Since they do different things, it is not really something that can be voted as "better" in an absolute sense, but given the wider capability of Split, if you ask me to vote for one of the functions in general terms, I vote split.

    The left function makes validInterface equal "a" in my example.
    While split will return
    validInterface(0) = "a"
    validInterface(1) = "b"
    validInterface(2) = "c"
    by having the (0) at the end (and I presume you know this already), you are simply accessing only the first item in the array for your result, but the computer still calculates and stores the others, making it less efficient if you don't want them.
    Last edited by Arkadi; 01-31-2017 at 02:27 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Style Question about extranting data from a string?

    I will let you ponder this:
    "There are 10 kinds of people in this world... those who understand binary, and those who don't." - - - " And, those that understand Gray Binary."

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Style Question about extracting data from a string?

    lol Good point.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Transform Data From Pivot Style to a Table Style
    By The_Snook in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-18-2016, 04:13 AM
  2. Font color and style to string
    By Zenderboy01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2013, 08:00 PM
  3. Normal Style to No Spacing Style by default.
    By dogberry in forum Word Formatting & General
    Replies: 1
    Last Post: 12-23-2012, 11:48 PM
  4. [SOLVED] Need to Convert Formula R1C1 into A1-style but the Formula String exceeds 255 characters
    By VBA_Gary in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-04-2012, 12:09 PM
  5. Billable hours per year style question
    By starr274 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-29-2009, 07:53 PM
  6. "if" style question based on certain dates...
    By RobMarshall in forum Excel General
    Replies: 6
    Last Post: 11-19-2007, 06:14 AM
  7. Replies: 4
    Last Post: 01-09-2006, 12:10 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1