How to get a value out from a string

Hi

I have a value like this

<span id="ad" number="assdf" object="adfff" telephone="0039393">aaaaaaa</span>

How do I get the vlaue of object?

so I should get the value

adfff

Please note object can be in any order in the span field.

thanks
mousemat24Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
something like this may help;

string val= "";
string[] words = s.Split(' ');
foreach (string word in words)
  if word.toLower().StartsWith('object=') { val = word.right(word.length-7).Trim("\"".ToCharArray()); break; }
0
 
käµfm³d 👽Commented:
Here's one approach:

string input = "<span id=\"ad\" number=\"assdf\" object=\"adfff\" telephone=\"0039393\">aaaaaaa</span>";
string[] parts = input.Split('=');
string value = string.Empty;

for (int i = 0; i < parts.Length; i++)
{
    if (parts[i] == "object")
    {
        value = parts[i + 1];
        break;
    }
}

Open in new window

0
 
sagirCommented:
Hi,

Does the span has runat="server" attribute? If so you can use
ad.Attributes["Object"].

If not, then I guess that this value would not be visible to the server side and hence you cannot extract value on your code behind...
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
käµfm³d 👽Commented:
Correction:

string input = "<span id=\"ad\" number=\"assdf\" object=\"adfff\" telephone=\"0039393\">aaaaaaa</span>";
string[] parts = input.Split('=');
string value = string.Empty;

for (int i = 0; i < parts.Length; i++)
{
    if (parts[i].EndsWith(" object"))
    {
        value = parts[i + 1];
        break;
    }
}

Open in new window

0
 
sagirCommented:
Ok, thought that you mean that you have the span on your aspx markup. If not then HainKurt's answer is  more appropriate.
0
 
mousemat24Author Commented:
HainKurt, there isnt a word.right in .NET?
0
 
xananduCommented:
although i am unfamiliar with c#, i would think the best way to do this would be to use .NET regular expressions to find the value as this kind of problem is the reason for regular expressions to exist.

the regex you are looking for would be simiar to
/object="(?<variablename>\w+)"/ where variablename is the callback you wish to assign to the object value.
0
 
käµfm³d 👽Commented:
I gets no love today  = (
0
All Courses

From novice to tech pro — start learning today.