Register for your free account! | Forgot your password?

You last visited: Today at 00:00

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



String problem

Discussion on String problem within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
String problem

Is not much of a conquer problem, but more a programming problem, but it's related to Conquer as it's for an ani editor.

So the problem is, when I'm reading the ids of the files, then the result is something like this:
Code:
561359
1
I have tried split with \n and check if the current char was alpha only, but it still does it :/

And when I copy it from the .ani file itself, then it would be:
Code:
5613591
So what could I do to make the itemid being normal? It's really bugging me ><

And this is how I get the item id:
Code:
            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i].StartsWith("["))
                {
                    ItemIDs.Add((Values[i] + 1).Replace("[Item", "").Replace("]", ""));
                }
            }
ItemIDs is a List<string>.

How I call it:
Code:
            foreach (string id in ItemIDs)
            {
                string select = comboBox1.SelectedItem.ToString();
                if (select == id)
                {
                    textBox1.Text = "Item" + id;
BaussHacker is offline  
Old 10/03/2011, 13:41   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
Two options...

#1: To get item ids that end in 0 (not equipment generally...)


itemID = itemID / 10 * 10;

#2: To get item ids that end in 5 (normal quality for equipment... non damaged non special versions)

if(itemID % 10 < 5)
itemID += 5 - newID % 10;

What this says in english (although I know you know what it does) is....

Take my id, divide it by 10 (gives me the LAST digit) and check if it's less than 5 (damaged or 'less than normal')

Now boost the ID by 5 - whatever it currently is (think about it... 1005 + 5-5 = 1005.... 1004 +5 - 4 = 1005. Simple logic)

Now you have to deal with other situations which are more likely


#3: You want to 'downgrade' all id's to a normal ID (IE: getting the base of a weapon maybe?)

itemID = itemID / 10 * 10 + 5;

That's the simplest way I can think of it. Just sets the last digit to 5 in this case (or whatever you want it to be really... set it to super if you wanted.


</sleepy post that probably completely bypasses the point of the thread>
pro4never is offline  
Old 10/03/2011, 14:18   #3
 
nTL3fTy's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 692
Received Thanks: 353
Quote:
Originally Posted by BaussHacker View Post
I have tried split with \n and check if the current char was alpha only, but it still does it :/
Environment.NewLine:
Code:
/*===================================NewLine==================================== 
        **Action: A property which returns the appropriate newline string for the given
        **        platform. 
        **Returns: \r\n on Win32. 
        **Arguments: None.
        **Exceptions: None. 
        ==============================================================================*/
        public static String NewLine {
            get {
                Contract.Ensures(Contract.Result<String>() != null); 
#if !PLATFORM_UNIX
                return "\r\n"; 
#else 
                return "\n";
#endif // !PLATFORM_UNIX 
            }
        }
Quote:
Originally Posted by BaussHacker View Post
And this is how I get the item id:
Code:
            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i].StartsWith("["))
                {
                    ItemIDs.Add((Values[i] + 1).Replace("[Item", "").Replace("]", ""));
                }
            }
You could use Substring:
Code:
var lines = new[] { "[ItemDefault]", "[Item50000]", "[Item3111000]" };
foreach (var line in lines)
{
    var sub = line.Substring(5, line.Length - 6);
    Console.WriteLine(sub);
}
Output:
Code:
Default
50000
3111000
nTL3fTy is offline  
Old 10/03/2011, 14:51   #4
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
Like I said already tried newline.

Quote:
Originally Posted by pro4never View Post
Two options...

#1: To get item ids that end in 0 (not equipment generally...)


itemID = itemID / 10 * 10;

#2: To get item ids that end in 5 (normal quality for equipment... non damaged non special versions)

if(itemID % 10 < 5)
itemID += 5 - newID % 10;

What this says in english (although I know you know what it does) is....

Take my id, divide it by 10 (gives me the LAST digit) and check if it's less than 5 (damaged or 'less than normal')

Now boost the ID by 5 - whatever it currently is (think about it... 1005 + 5-5 = 1005.... 1004 +5 - 4 = 1005. Simple logic)

Now you have to deal with other situations which are more likely


#3: You want to 'downgrade' all id's to a normal ID (IE: getting the base of a weapon maybe?)

itemID = itemID / 10 * 10 + 5;

That's the simplest way I can think of it. Just sets the last digit to 5 in this case (or whatever you want it to be really... set it to super if you wanted.


</sleepy post that probably completely bypasses the point of the thread>
ID is from MapItemIco.ani and ItemMinIco.ani
BaussHacker is offline  
Old 10/03/2011, 15:03   #5


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Can you paste some example text your trying to read? I never had this problem when i was reading from ani files.
Korvacs is offline  
Old 10/03/2011, 15:10   #6
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
Quote:
Originally Posted by Korvacs View Post
Can you paste some example text your trying to read? I never had this problem when i was reading from ani files.
Code:
            ItemIDs = new List<string>();
            string[] Values;
            FileStream fs = new FileStream(Environment.CurrentDirectory + "\\ani\\" + comboBox2.SelectedItem.ToString() + ".ani", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            Values = sr.ReadToEnd().Split('\n');
            sr.Close();
            fs.Close();

            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i].StartsWith("["))
                {
                    ItemIDs.Add((Values[i] + 1).Replace("[Item", "").Replace("]", ""));
                }
            }
            foreach (string itemid in ItemIDs)
                comboBox1.Items.Add(itemid);
BaussHacker is offline  
Old 10/03/2011, 15:44   #7


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
That wasnt quite what i meant, but its like this for any ani file?
Korvacs is offline  
Old 10/03/2011, 15:48   #8
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
Quote:
Originally Posted by Korvacs View Post
That wasnt quite what i meant, but its like this for any ani file?
Haven't tried others. I will try and look, but I don't think it's the file as I can copy it from the file and it's all normal ><
BaussHacker is offline  
Old 10/03/2011, 15:50   #9


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Which file is it specifically.

Well either way, my advice would be to ditch your "Values = sr.ReadToEnd().Split('\n');" and instead go with:

Code:
while ((CurrentLine = Reader.ReadLine()) != null)
And then for every line perform your filtering to get item ids and add them to the list.

For example, this is how i handle .ani files in my .wdf extractor, i realise that its not identical to what your trying to do, but you could do something similar certainly.

Code:
foreach (string _File in Directory.GetFiles(ConquerFolder + "\\ani"))
                {
                    FileStream InputFile = new FileStream(_File, FileMode.Open);
                    TextReader Reader = new StreamReader(InputFile);

                    string CurrentLine = string.Empty;
                    string Path = string.Empty;
                    uint Key = 0;

                    while ((CurrentLine = Reader.ReadLine()) != null)
                    {
                        if (!CurrentLine.StartsWith("Frame") || CurrentLine.StartsWith("FrameAmount"))
                            continue;

                        string[] Data = CurrentLine.Split('=');

                        if (Data.Length < 2)
                            continue;

                        Path = Data[1];

                        Key = Shared.CalculateStringHash(Path);
                        if (!_HashList.ContainsKey(Key))
                            _HashList.Add(Key, Path);
                    }
                }
Korvacs is offline  
Thanks
1 User
Old 10/03/2011, 16:15   #10
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
It's ItemMinIco.ani and I will try that thank you.

Thanks Korvacs, yours example worked.
BaussHacker is offline  
Reply


Similar Threads Similar Threads
Need String
08/20/2011 - Rappelz - 7 Replies
Hi, I wanted to ask if there was a command to Auto-restart the server after the crash.
[VB08]String in String mit mehreren Funden
08/08/2011 - .NET Languages - 6 Replies
Hey, bin gerade auf ein Problem gestoßen, an dem ich mir seit 3 Stunden die Zähne ausbeiße. Ich will eine Funktion schreiben, die der _StringBetween Funktion von AutoIt gleich ist. _StringBetween gibt in einem Array alle Strings zwischen zwei SubStrings und dem ganzen String aus. Die Ausgabe bei _StringBetween("<h1>test1</h1>&l t;h1>test2</h1>", "<h1>", "</h1>") wäre also idealer Weiße ein Array (x = "test1", x = "test2")... da man in VB08 kein Array returnen kann, komme ich aber einfach...
[C++] string zwischen string
11/11/2010 - C/C++ - 6 Replies
tag gibts direkt ne funktion, mit der man einen passenden string zwischen dem string suchen kann? also meine net .find() sondern sowas ähnliches, die in diesem beispiel "mein string sucht" Bsp: "<span id=\"lalala\">"+string mein_string+"</span>" understanden? :-)
String.au3
09/11/2010 - AutoIt - 2 Replies
Hey, hat jemand die Datei für mich? Ich finde im Internet nichts (ich hoffe ich habe nichts übersehn) Mfg
[C++]Dev C++ string to int
08/06/2010 - C/C++ - 25 Replies
Schonwieder ich :P Also ich versuchs ma gut zu beschreiben. Ich habe nen string in dem steht 1 und bevor einer fragt warum ich nicht direkt int benutzte es würde dan nicht funktioniern. Also ich möchte den string in dem 1 steht in eine int variable umwandeln und danach irgendwan wieder zurück wie schaffe ich das? mit atoi habe ich es nicht hingekriegt und auch nicht mit strtoint



All times are GMT +2. The time now is 00:00.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.