473,503 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the longest string?

XML

<data>
<option>this is test 1</option>
<option>this is test 11</option>
<option>this is test 111</option>
<option>this is test 1111</option>
<option>this is test 11111</option>
</data>

The 5 option has the longest content. I need to get that length and place
in a variable. The test has to look across all of the option nodes and
return the longest one.

Any suggestions?

Cheers
Keith
Nov 12 '05 #1
1 1282
Sample code
static void Main(string[] args)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<data><option>this is test 1</option>" +
"<option>this is test 11</option><option>this is test 111</option>" +
"<option>this is test 1111</option><option>this is test 11111</option>" +
"</data>");
int pos = 0;
foreach (System.Xml.XmlElement e in doc.DocumentElement.SelectNodes("option"))
{
if (e.InnerText.Length > pos)
{
pos = e.InnerText.Length;
}
}
}

Hope this helps,

Randy
http://www.kbcafe.com

"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message news:<uk**************@TK2MSFTNGP12.phx.gbl>...
XML

<data>
<option>this is test 1</option>
<option>this is test 11</option>
<option>this is test 111</option>
<option>this is test 1111</option>
<option>this is test 11111</option>
</data>

The 5 option has the longest content. I need to get that length and place
in a variable. The test has to look across all of the option nodes and
return the longest one.

Any suggestions?

Cheers
Keith

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
4568
by: Nick Mudge | last post by:
Hey everybody, let's make the longest newsgroup thread ever made. Find the posting "Any girls?" in this newsgroup and add a posting. The name of the thread is a great name for a programming...
12
2937
by: Joerg Schuster | last post by:
Hello, The program given below returns the lines: a ab Is there a way to use python regular expressions such that the program would return the following lines?
2
2559
by: Keith Chadwick | last post by:
XML <data> <option>this is test 1</option> <option>this is test 11</option> <option>this is test 111</option> <option>this is test 1111</option> <option>this is test 11111</option> </data>
6
4473
by: Kwok | last post by:
Hi All, I want to make the longest string value (it probables more than 300 words.) to more rows to print it using printDocument. How do i do it like WORD that it auto cut string value at...
32
14610
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
1
3982
by: iElf | last post by:
can someone point out my error? cus this is printing out garbage and not the longest word... Program ( I underlined the loop Im trying to make to read and find the longest word) everything else...
4
5245
by: vicestner | last post by:
Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and...
2
1325
by: longhorn | last post by:
Hello, I'm looking for a macro that will return the longest range of ones in an unsigned integer, along with starting and ending position. For example I have an unsigned int data that looks...
9
2980
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.