5 Replies - 418 Views - Last Post: 02 September 2012 - 08:52 AM Rate Topic: -----

#1 nesa24casa  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 25-August 12

C# Retrive value from string to text box

Posted 02 September 2012 - 08:24 AM

Hello again,
i have strings from html file's.
string1 from html1
Banana=15,Popcorn=20,HotDog=20

string2 from html2
Sweet=12,Banana=15,Magazine=30


How can i get just value from a string to textBox.Text= if i dont know its position in string (htmlfile) ?


Thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: C# Retrive value from string to text box

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4437
  • View blog
  • Posts: 12,308
  • Joined: 18-April 07

Re: C# Retrive value from string to text box

Posted 02 September 2012 - 08:30 AM

Split it on the commas, then take each piece and split it on the "=". It will be the second piece of the split.

Just one way. :)
Was This Post Helpful? 2
  • +
  • -

#3 nesa24casa  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 25-August 12

Re: C# Retrive value from string to text box

Posted 02 September 2012 - 08:46 AM

Well i connect to
http://www.transfermarkt.co.uk/en/juventus-fc/kader/verein_506.html

download file as juve.html

Than use
string s =File.ReadAllText("C:/juve.html");

and i get file into string

How can i get Buffon age from it to textbox?

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,210
  • Joined: 02-June 10

Re: C# Retrive value from string to text box

Posted 02 September 2012 - 08:49 AM

I agree 100%

string[] eachSetting = htmlString.Split(',');
// This give you
// eachSetting[0] == Banana=15
// eachSetting[1] == Popcorn=20



Then you can loop through the array as needed doing a .Split on the '=' to separate the name of the setting from the value of the setting.

foreach(string s in eachSetting)
{
   string[] temp = s.Split('=');
   string theName = temp[0];
   int theValue; 
   int.TryParse(temp[1], out theValue);
}

Was This Post Helpful? 2
  • +
  • -

#5 nesa24casa  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 25-August 12

Re: C# Retrive value from string to text box

Posted 02 September 2012 - 08:51 AM

Can you please post Buffon age example?
Just to see if i get it right.
Was This Post Helpful? -1
  • +
  • -

#6 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4437
  • View blog
  • Posts: 12,308
  • Joined: 18-April 07

Re: C# Retrive value from string to text box

Posted 02 September 2012 - 08:52 AM

What in the world does this have to do with the original question? I thought you said you had a string in the format "name=num,name2=num2,name3=num3"?

As for pulling out text from a page, look at using a regular expression and specifically creating a Pattern.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1