Results 1 to 4 of 4

Thread: String Retrieval

  1. #1
    Frenzied Member
    Join Date
    Jun 05
    Posts
    1,138

    String Retrieval

    I have a string like this:

    font-family:Arial;font-size:10px;color:green;

    I would like to retrieve the string like this:
    Arial;10px;green

    How do I accomplish this ?

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 07
    Location
    Land Down Under
    Posts
    1,256

    Re: String Retrieval

    Do you use regular expressions or would string functions be better?
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,729

    Re: String Retrieval

    Hello,

    Am I right in saying that you are parsing HTML that you are getting from "somewhere"?

    If so, you might want to take a look at the HTMLAgilityPack:

    http://htmlagilitypack.codeplex.com/

    Which I am fairly sure has methods for getting at this data.

    Gary

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 04
    Location
    Inside the CPU...
    Posts
    6,474

    Re: String Retrieval

    You can use Regular expressions for your purpose. This is possible both ways - javascript as well as server side asp.net code, since both support Regular experessions in one form or the other.

    The following Regex expression will help get you the relevent parts:
    Code:
    (?<=:).+?(?=;)
    Here's the strategy:
    Use the regex expression I provided above to get the required parts. You will obviously get them in separate groups/sub-groups. All you need to do after that is to join/concatenate them with a semi-colon in between.

    Let me know if you need some sample code and I'll try to quickly construct one.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog • 101 LINQ Samples • JSON Validator • XML Schema Validator • "How Do I" videos on MSDN • VB.NET and C# Comparison • Good Coding Practices • VBForums Reputation Saver • String Enum • Super Simple Tetris Game


    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

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