5 Replies - 322 Views - Last Post: 07 December 2012 - 08:52 AM Rate Topic: -----

#1 visweswaran28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 29-October 09

How to select specific field value in a string

Posted 07 December 2012 - 03:03 AM

Hi,


<DIV style="POSITION: absolute; TEXT-ALIGN: center; FONT-STYLE: normal; WIDTH: 141px; FONT-FAMILY: Arial; WHITE-SPACE: nowrap; HEIGHT: 76px; FONT-SIZE: 12pt; TOP: 268px; FONT-WEIGHT: 400; TEXT-DECORATION: none; ctrlProp="acknowledged:true;showDisableIcon:True;showTooltip:True;sizeableIcon:True;"></DIV>

Consider the above string, Now I want to know the value of sizeableIcon (Either true/false),showDisableIcon (either true /false). Is there any way to pick those values.

Note: I don't want to use split(";") method. It should be professional way.

Is This A Good Question/Topic? 0
  • +

Replies To: How to select specific field value in a string

#2 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,500
  • Joined: 08-April 09

Re: How to select specific field value in a string

Posted 07 December 2012 - 03:25 AM

Well you could try with String.Substring Method
Was This Post Helpful? 0
  • +
  • -

#3 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: How to select specific field value in a string

Posted 07 December 2012 - 05:46 AM

Professional way ;) ?
Use Regex class:

            var str = //your string here 
            MatchCollection extractedTextResults = Regex.Matches(str, "(?<=sizeableIcon:)(.*?)(?=;)/>");
            foreach (Match match in extractedTextResults)
            {
               //do something wit each match
            }


Was This Post Helpful? 0
  • +
  • -

#4 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: How to select specific field value in a string

Posted 07 December 2012 - 05:52 AM

In my previous post is error, and I can't fix it due to forum bug. Notice at the end of line 2: />"); should be without />.

So the line would look:
MatchCollection extractedTextResults = Regex.Matches(str, "(?<=sizeableIcon:)(.*?)(?=;)");

Seems to work with IL tag.
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4433
  • View blog
  • Posts: 7,702
  • Joined: 08-June 10

Re: How to select specific field value in a string

Posted 07 December 2012 - 08:20 AM

Regex is fine, if you know the metalanguage. But for most people who haven't learned it, you know the old saying "A programmer has a problem. He says, 'I know, I'll solve it with regular expressions!' Now he has two problems."

I do take issue with calling "Split" unprofessional, considering it's one of the most useful tools in the String class.

Also, you could parse the tag as XML, then get the attribute, and split it. Or you could use the HTMLAgilityPack if you're dealing with lots of HTML. With either of those methods, you'll have to split the attribute on ';'.
Was This Post Helpful? 1
  • +
  • -

#6 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,500
  • Joined: 08-April 09

Re: How to select specific field value in a string

Posted 07 December 2012 - 08:52 AM

Quote

Also, you could parse the tag as XML, then get the attribute, and split it


I forgot about that :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1