SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting a substring

    I'm new to asp.net.

    compatabilityInfo.Text += "<br><b>" + reader.GetString(1) + "/b>&nbsp;" + reader.GetString(2);


    compatabilityInfo is the id of a literal control. After the above string is concatenated I need to remove the first 4 characters ( the first "<br>" ).

    I was going to build a substring starting at the third character and going to the last. I'm wondering if I can treat compatability.Text just like any other string. Or is it different because it's referencing a literal control?

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    You can do exactly that.

    compatabilityInfo.Text = compatabilityInfo.Text.Substring(4);

    or

    compatabilityInfo.Text = compatabilityInfo.Text.Replace("<br>",""); //This will remove all <br> occurrences in the string if you need to.

    I hope this helps

  3. #3
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked, thank you. Does Substring(4) only need a second value if I was not trying to extract up to the last character?

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tictike
    That worked, thank you. Does Substring(4) only need a second value if I was not trying to extract up to the last character?
    Yes, thats correct. The second parameter is length. So you can set how many chars you want to get back, and if left out just goes to the end of the string


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
  •