Results 1 to 4 of 4

Thread: [RESOLVED] Substring Issues

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2008
    Posts
    159

    Resolved [RESOLVED] Substring Issues

    Hi all,

    I'm having an issue with a substring. I have the following.

    Code:
    string PV = "INSTL-PLATE,REAR WALL"
    
    string t1 = PV.Substring(0, PV.IndexOf('-'));
    string t2 = PV.Substring(PV.IndexOf('-') +1, PV.IndexOf(','));
    string t3 = PV.Substring(PV.IndexOf(',') +1);
    When I split these I should get the following (or at least this is what I want...)

    t1 = INSTL
    t2 = PLATE
    t3 = REAR WALL

    t1 & t3 work correctly. When I run it t2 = PLATE,REAR

    What am I missing???

    Thanks!

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Substring Issues

    the second parameter is the LENGTH to retrieve.... not the stop index. So you need to get the indexof the ',' then subtract the start index, which will then give you the length to return.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Substring Issues

    Okay, here is what TG suggesting.
    Code:
    string t2 = PV.Substring(PV.IndexOf('-') + 1, PV.IndexOf(',') - PV.IndexOf('-') - 1);
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2008
    Posts
    159

    Re: Substring Issues

    Thanks all! This got it for me... I get messed up sometimes when trying to break down these strings... Appreciate the help!

Posting Permissions

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



Click Here to Expand Forum to Full Width