Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 23:07

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

Advertisement



C# Help, Reading Files

Discussion on C# Help, Reading Files within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
C# Help, Reading Files

Hey, i cant seem to get my head around this,

What im trying to do is, Read a line from a file but, i want to single out each word and save it into a String array, using the "Trim()" command? but i just cant do it, if you can point me in the right direction it would be nice ;D
xScott is offline  
Old 02/26/2010, 23:19   #2
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
PHP Code:
string[] ReadFile(string Path) {
    if(
File.Exists(Path)) {
        return 
File.ReadAllText(Path).Split('\n');
    }
    return 
null;

Something like that? This one reads the whole file though.

PHP Code:
string[] ReadFile(string Pathint Line) {
    if(
File.Exists(Path)) {
        return 
File.ReadAllLines(Path)[Line].Split('\n');
    }
    return 
null;

This one reads the specified line.
tanelipe is offline  
Thanks
2 Users
Old 02/26/2010, 23:25   #3
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
Quote:
Originally Posted by tanelipe View Post
PHP Code:

string
[] ReadFile(string Path) {
    if(
File.Exists(Path)) {
        return 
File.ReadAllText(Path).Split('\n');
    }
    return 
null;

Something like that?
ermm, i think so, im not sure xD ill give it a try ;o
xScott is offline  
Old 02/27/2010, 00:13   #4
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
well tanel he said each word your splitting each line

you could do like
C# aint open so just writing
Code:
string[] lines = File.ReadAllLines("mylines.txt");

foreach (string line in lines)
{
    string[] words = line.split(' ');

}
PeTe Ninja is offline  
Thanks
1 User
Old 02/27/2010, 01:00   #5
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
Quote:
Originally Posted by PeTe Ninja View Post
well tanel he said each word your splitting each line

you could do like
C# aint open so just writing
Code:
string[] lines = File.ReadAllLines("mylines.txt");

foreach (string line in lines)
{
    string[] words = line.split(' ');

}
thanks both of you :]

Code:
 string[] lines = File.ReadAllLines(@"C:\Users\ADVENT\Documents\Questions.txt");
            foreach (string line in lines)
            {
                string[] words = line.Split(' ');
                for (int i = 0; i < words.Length; i++)
                {
                    Console.WriteLine(words[i]);
                }

            }
got all the words to show in console, cheers its what i wanted ;]
xScott is offline  
Old 02/27/2010, 01:38   #6
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
C++ File Viewer

Quote:
Originally Posted by xScott View Post
thanks both of you :]

Code:
 string[] lines = File.ReadAllLines(@"C:\Users\ADVENT\Documents\Questions.txt");
            foreach (string line in lines)
            {
                string[] words = line.Split(' ');
                for (int i = 0; i < words.Length; i++)
                {
                    Console.WriteLine(words[i]);
                }

            }
got all the words to show in console, cheers its what i wanted ;]
Here is another pretty cool file viewer

i made it in C++

Check attachment..
Attached Files
File Type: rar File Viewer.rar (104.2 KB, 5 views)
PeTe Ninja is offline  
Thanks
1 User
Old 02/27/2010, 01:40   #7
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
im getting confused, 1element in the array holds 3 words but in differant lines, so its possible to save the 3 words into 3 differant string variables?

and thats pretty decent, you make it yourself?
xScott is offline  
Old 02/27/2010, 01:48   #8
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
Quote:
Originally Posted by xScott View Post
im getting confused, 1element in the array holds 3 words but in differant lines, so its possible to save the 3 words into 3 differant string variables?

and thats pretty decent, you make it yourself?
yeah i was learning C++ a while ago from youtube videos and it had a guide somewhat similar and then i made this one a bit more advanced so it works good but yeah i made it

anyway on your thing is this what you kind of need? 3 diff words 3 diff strings

Code:
string a = "";
            string b = "";
            string c = "";

            string[] lines = File.ReadAllLines(@"C:\Users\ADVENT\Documents\Questions.txt");
            foreach (string line in lines)
            {
                string[] words = line.Split(' ');
                for (int i = 0; i < words.Length; i++)
                {
                    a = words[0];
                    b = words[1];
                    c = words[2];
                    Console.WriteLine(words[i]);
                }

            }
PeTe Ninja is offline  
Thanks
1 User
Old 02/27/2010, 01:59   #9
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
Quote:
Originally Posted by PeTe Ninja View Post
yeah i was learning C++ a while ago from youtube videos and it had a guide somewhat similar and then i made this one a bit more advanced so it works good but yeah i made it

anyway on your thing is this what you kind of need? 3 diff words 3 diff strings

Code:
string a = "";
            string b = "";
            string c = "";

            string[] lines = File.ReadAllLines(@"C:\Users\ADVENT\Documents\Questions.txt");
            foreach (string line in lines)
            {
                string[] words = line.Split(' ');
                for (int i = 0; i < words.Length; i++)
                {
                    a = words[0];
                    b = words[1];
                    c = words[2];
                    Console.WriteLine(words[i]);
                }

            }
thanks! ill play around with it for abit, so i get abit more familiar with it, cheers for your help
xScott is offline  
Old 02/27/2010, 02:07   #10
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
np =]
PeTe Ninja is offline  
Thanks
1 User
Old 02/27/2010, 03:51   #11
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Quote:
Originally Posted by xScott View Post
Hey, i cant seem to get my head around this,

What im trying to do is, Read a line from a file but, i want to single out each word and save it into a String array, using the "Trim()" command? but i just cant do it, if you can point me in the right direction it would be nice ;D
This is not necessarily the most efficient way to do it but...
Code:
// using System.IO
// using System.Collections.Generic
public static string[] ReadAllWords(string File)
{
	// Note: An exception will be thrown here if the file does not exist
	string[] Lines = File.ReadAllLines(File);
	List<string> Words = new List<string>();
	foreach (string line in Lines)
	{
		foreach (string s in line.Split(' '))
			Words.Add(s);
	}
	return Lines.ToArray();
}
InfamousNoone is offline  
Thanks
1 User
Old 02/27/2010, 04:00   #12
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
Quote:
Originally Posted by InfamousNoone View Post
This is not necessarily the most efficient way to do it but...
Code:
// using System.IO
// using System.Collections.Generic
public static string[] ReadAllWords(string File)
{
	// Note: An exception will be thrown here if the file does not exist
	string[] Lines = File.ReadAllLines(File);
	List<string> Words = new List<string>();
	foreach (string line in Lines)
	{
		foreach (string s in line.Split(' '))
			Words.Add(s);
	}
	return Lines.ToArray();
}
well if it aint infamous..where u been hiding
PeTe Ninja is offline  
Old 02/27/2010, 04:03   #13
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
Quote:
Originally Posted by InfamousNoone View Post
This is not necessarily the most efficient way to do it but...
Code:
// using System.IO
// using System.Collections.Generic
public static string[] ReadAllWords(string File)
{
	// Note: An exception will be thrown here if the file does not exist
	string[] Lines = File.ReadAllLines(File);
	List<string> Words = new List<string>();
	foreach (string line in Lines)
	{
		foreach (string s in line.Split(' '))
			Words.Add(s);
	}
	return Lines.ToArray();
}
cheers ill give it a go xD
xScott is offline  
Old 02/27/2010, 04:05   #14
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
Quote:
Originally Posted by xScott View Post
cheers ill give it a go xD



infamous is it better to use a list or an array?
PeTe Ninja is offline  
Old 02/27/2010, 04:34   #15
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
I was playing around with it for abit and managed to make it do what i wanted :
Code:
public static string[] ReadAllWords()
        {
            
            // Note: An exception will be thrown here if the file does not exist
            string[] Lines = File.ReadAllLines(@"C:\Users\ADVENT\Documents\Questions.txt");
            List<string> Words = new List<string>();
            foreach (string line in Lines)
            {
                foreach (string s in line.Split(' '))
                    Words.Add(s);
            }
            string[] ArrayWords = new string[Words.Count];
            Words.CopyTo(ArrayWords);
            for(byte i = 0; i < ArrayWords.Length ; i++)
            {
                Console.WriteLine(ArrayWords[i]);
            }
            return Lines.ToArray();
        }
its probably terrible, but im working with stuff i aint used before such as lists. ill have a play around with it xD
xScott is offline  
Reply


Similar Threads Similar Threads
Reading HP/MP/etc...
10/27/2009 - Aion - 2 Replies
Hey All, I'm sort of new to this memory offset, but I've currently got the BaseAddress of Game.dll and am looking for advice or direction in getting the target HP and stuff. I've seen the offset thread on these forums, I'm just unsure how to actually do the offset in C#. Any direction would be appreciated :)
upon reading....
07/01/2009 - Grand Chase - 23 Replies
upon reading this forum. i noticed that majority is blaming the cheater for being patch well guys i want you to under stand that game guard will always be updated every two or three weeks...
Problem when reading the downloaded files
02/26/2009 - Zero - 2 Replies
Can anyone help me after i downloaded the .rar file then ill use my winRAR to extract it all it says is ! D:\Documents and Settings\Desktop\7234d1191457676-cheat-engine-disc ussion-submission-zeroonline.rar: The archive is either in unknown format or damaged how can that be when its a small file so it wont be damaged? can anyone give me an advice. thank you Sirs..
[HELP]Writing and reading from *.ini files
02/18/2009 - CO2 Programming - 2 Replies
i was trying to do that by myself but after 3days i must say that i cant do it :mad: sooo i will be very happy if somebody could help me with it :) thanks :)
Reading and Writing .INI Files
11/16/2008 - General Coding - 2 Replies
CodeGuru: CIniFile - Class for Reading and Writing .INI Files I found this information useful for starting out on understanding more about the code for read/write ini files. Maybe this will help some others (That are willing to read) :D enjoy



All times are GMT +1. The time now is 23:08.


Powered by vBulletin®
Copyright ©2000 - 2026, 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 ©2026 elitepvpers All Rights Reserved.