Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 04-19-2007, 01:22 AM   #1 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default ToUpper() ToString()

in this line how can i take all entries and add them to string with all upper cap?

for (int i = 0; i < nodItems.Count; i++)
itemcheckarray[i] = nodItems[i].InnerText.ToUpper ToString();

***edit** nm i found out, bt now the problem is i cant get them back to the original before printing it, so i made that.

Code:
string strsearchentry = this.textBox1.Text.ToUpper();
            XmlElement nodRoot = docXML.DocumentElement;
            XmlNodeList nodItems = nodRoot.GetElementsByTagName("nom");
            int p = nodItems.Count;

            string[] itemsarray = new string[p];
            string[] itemsarrayor = new string[p];

            for (int i = 0; i < nodItems.Count; i++)
            {
                itemsarray[i] = nodItems[i].InnerText.ToUpper();
                itemsarrayor[i] = nodItems[i].InnerText.ToString();
            }
so basicly i get the same array twice but one for printing on form and the other for search matter what i want to do is get the offest value of the item it will return in this piece of code.

Code:
foreach (string item in itemsarray)
            {
                if (item.Contains(strsearchentry))
                {
                    offset = 3;//****get the offset of the item entry***
                    //call method to add the original item entry to a list box that need the offset value of the item
                }
            }
__________________
Admin of Crystal World, French shard
Under Construction
http://www.crystalworld.over-blog.com/
If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation.

Last edited by jocan2003; 04-19-2007 at 01:51 AM.
jocan2003 is offline   Reply With Quote
Old 04-19-2007, 01:41 AM   #2 (permalink)
RunUO Forum Moderator
 
daat99's Avatar
 
Join Date: Dec 2004
Location: Israel
Age: 27
Posts: 8,163
Send a message via ICQ to daat99 Send a message via AIM to daat99
Default

Quote:
Originally Posted by jocan2003 View Post
in this line how can i take all entries and add them to string with all upper cap?

for (int i = 0; i < nodItems.Count; i++)
itemcheckarray[i] = nodItems[i].InnerText.ToUpper ToString();
Assuming nodItems can have 5 items or more in it I would use the stringBuilder class to acompish that:

Code:
stringBuilder sb = new stringBuilder();
for (int i=0; i<nodItems.Count; i++)
   sb.Append(nodItems[i].InnerText.ToUpper().ToString());
string fullString = sb.ToString();
__________________
I always try to help
Sometimes, I don't know how....

My Web Page
Forum Rules
-------------------------------------------------------------
Extensive OWLTR System | Token System | World Teleporters
-------------------------------------------------------------
daat99 is offline   Reply With Quote
Old 04-19-2007, 02:23 AM   #3 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

it doesnt tell me the offest the value will used, thats the only thing i need ot know for now, beside that i got everything working, well maybe not now because i mess a lot trying to find a way, but i have a working copy just before i mess out .

First i started by declaring some parameter wich are these one.
Code:
private int _offset;
        private string[] _itemsarrayor;
        private string _stradd;

        public int offset
        {
            get { return _offset; }
            set { _offset = value; }
        }

        public string[] itemsarrayor
        {
            get { return _itemsarrayor; }
            set { _itemsarrayor = value; }
        }

        public string stradd
        {
            get { return _stradd; }
            set { _stradd = value; }
        }
then i made a method that will return a value to me
Code:
private string SendOValue( int offset )
        {
            return stradd = itemsarrayor[offset].ToString();
        }
then, well there we are... the famous structure where i need to find the offset
Code:
 private void button3_Click(object sender, EventArgs e)
        {
            

            Form2 fm = new Form2();
            XmlDocument docXML = new XmlDocument();

            docXML.Load("Liste.xml");

            string strsearchentry = this.textBox1.Text.ToUpper();
            XmlElement nodRoot = docXML.DocumentElement;
            XmlNodeList nodItems = nodRoot.GetElementsByTagName("nom");
            int p = nodItems.Count;

            string[] itemsarray = new string[p];
            string[] itemsarrayor = new string[p];

            for (int i = 0; i < nodItems.Count; i++)
            {
                itemsarray[i] = nodItems[i].InnerText.ToUpper();
                itemsarrayor[i] = nodItems[i].InnerText.ToString();
            }

            foreach (string item in itemsarray)
            {
                if (item.Contains(strsearchentry))
                {
                    offset = ?? ;//****get the offset of the item entry***
                    stradd = SendOValue(offset);
                    fm.listBox1.Items.Add(stradd);
                }
            }            
            fm.Show();
can you tell me how i can get the offset number the item have inside the itemsarray at this place.
Code:
foreach (string item in itemsarray)
            {
                if (item.Contains(strsearchentry))
                {
                    offset = ?? ;//****get the offset of the item entry***
                    stradd = SendOValue(offset);
                    fm.listBox1.Items.Add(stradd);
                }
            }
thanks you daat
__________________
Admin of Crystal World, French shard
Under Construction
http://www.crystalworld.over-blog.com/
If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation.
jocan2003 is offline   Reply With Quote
Old 04-19-2007, 09:29 AM   #4 (permalink)
Forum Expert
 
TheOutkastDev's Avatar
 
Join Date: Sep 2002
Location: Houston, Texas
Age: 21
Posts: 3,933
Default

Use a List<string> instead of an array. List<T> has an IndexOf function that will return the position in the array if the string is in it.
TheOutkastDev is offline   Reply With Quote
Old 04-19-2007, 06:47 PM   #5 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

thanks instead i made a new int with value 0 and time it was itarating a new time int was increased by one, wich worked fine.
__________________
Admin of Crystal World, French shard
Under Construction
http://www.crystalworld.over-blog.com/
If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation.
jocan2003 is offline   Reply With Quote
Old 04-19-2007, 11:28 PM   #6 (permalink)
Forum Expert
 
TheOutkastDev's Avatar
 
Join Date: Sep 2002
Location: Houston, Texas
Age: 21
Posts: 3,933
Default

Quote:
Originally Posted by jocan2003 View Post
thanks instead i made a new int with value 0 and time it was itarating a new time int was increased by one, wich worked fine.
ok.
TheOutkastDev is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5