Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. parsing a string

parsing a string

Scheduled Pinned Locked Moved C#
csharpphpdata-structuresjsontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Camron
    wrote on last edited by
    #1

    I'm brand new to C# and I'm trying to figure out how to parse a string. Is there a function available much like the explode() function in PHP which breaks up the string on a certain character and places the different parts into an array?

    D L 2 Replies Last reply
    0
    • C Camron

      I'm brand new to C# and I'm trying to figure out how to parse a string. Is there a function available much like the explode() function in PHP which breaks up the string on a certain character and places the different parts into an array?

      D Offline
      D Offline
      Darryl Borden
      wrote on last edited by
      #2

      string s = "a,b,c"; string[] parsed = s.Split(','); Darryl Borden Principal IT Analyst dborden@eprod.com

      1 Reply Last reply
      0
      • C Camron

        I'm brand new to C# and I'm trying to figure out how to parse a string. Is there a function available much like the explode() function in PHP which breaks up the string on a certain character and places the different parts into an array?

        L Offline
        L Offline
        LighthouseJ
        wrote on last edited by
        #3

        Well, one thing I'm doing is this. I have a String variable called 'filename' which contains the entire path and filename, including extension. I want just the filename, no directories or extensions. To do this, I have this one command:

        String shortened = Filename.Substring(Filename.LastIndexOf("\\") + 1, Filename.LastIndexOf(".") - Filename.LastIndexOf("\\") - 1);

        LastIndexOf() figures out the number position of the last one of that kind of character. Substring() extracts out n number of characters starting at position m, where the arguments are .Substring(m, n) C# isn't meant to parse out strings like PHP, PERL and others but I think you can find quite suitable alternatives using those methods and possibly others.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups