473,569 Members | 2,788 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 1290
Sample code
static void Main(string[] args)
{
System.Xml.XmlD ocument doc = new System.Xml.XmlD ocument();
doc.LoadXml("<d ata><option>thi s is test 1</option>" +
"<option>th is is test 11</option><option> this is test 111</option>" +
"<option>th is is test 1111</option><option> this is test 11111</option>" +
"</data>");
int pos = 0;
foreach (System.Xml.Xml Element e in doc.DocumentEle ment.SelectNode s("option"))
{
if (e.InnerText.Le ngth > pos)
{
pos = e.InnerText.Len gth;
}
}
}

Hope this helps,

Randy
http://www.kbcafe.com

"Keith Chadwick" <kc*******@leew ardsystems.com> wrote in message news:<uk******* *******@TK2MSFT NGP12.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
4577
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 newsgroup, but i wish the content was better than it currently is, so write some good stuff!! and let's make a record. The thread is already really long....
12
2942
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
2567
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
4477
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 space character.
32
14631
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 engine doesn't exaust all the
1
3990
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 works perfectly: #include <stdio.h> #include <string.h>
4
5254
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 punctuation in the input. If there are more than one palindrome of the maximum length, print the first one. Remove all space and punctuation and convert upper...
2
1333
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 like: bit pos: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 .... 00 data 0 1 1 1 1 0 1 1 0 1 0 1 1 0 ... 0
9
2987
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 directory. Assume that all contents of all the files may be held in memory at the same time. Do not use unsafe code blocks and/ or pointers.
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.