Getting substring from a line
-
So I read a file and that file has like 9k lines. the lines look like this(well it might not fit here, but is on a line only): A:"extatic" A:"extatici" A:"extaticul" A:"extaticului" A:"extaticii" A:"extaticilor" A:"extatică" A:"extatice" A:"extatica" A:"extaticei" A:"extaticele" A:"extaticelor" And I use textreader in c# to find a char in that text for example "extaticele" here. What I want is to extract if I found the char on that line the first char on that line. In this case "extatic" - but without "" of course and paste it in a text file. I dont know exactly how to work with find space so I want your help...cause I thought I'd find the first space in the line then take the index and with the index 0 of the line to extract "A:"extatic" ". Then remove the "A:" and the ". I saw somewhere an example with myString.find("") , but I can't find the "find" I might need a namespace.
-
So I read a file and that file has like 9k lines. the lines look like this(well it might not fit here, but is on a line only): A:"extatic" A:"extatici" A:"extaticul" A:"extaticului" A:"extaticii" A:"extaticilor" A:"extatică" A:"extatice" A:"extatica" A:"extaticei" A:"extaticele" A:"extaticelor" And I use textreader in c# to find a char in that text for example "extaticele" here. What I want is to extract if I found the char on that line the first char on that line. In this case "extatic" - but without "" of course and paste it in a text file. I dont know exactly how to work with find space so I want your help...cause I thought I'd find the first space in the line then take the index and with the index 0 of the line to extract "A:"extatic" ". Then remove the "A:" and the ". I saw somewhere an example with myString.find("") , but I can't find the "find" I might need a namespace.
In .Net, reference types are also objects. That means that most of the commands that you are looking for are present in the string itself. You can play with stuff like: String test = "abcd"; int index = test.IndexOf('b'); String test2 = test.Substring(index); // etc... There are plenty of methods on the string object. There are also static methods in the String class, like for example: String.Compare(string1, string2...) Last but not least, the namespace you are looking for is simply System.
Jean-Christophe Grégoire
-
In .Net, reference types are also objects. That means that most of the commands that you are looking for are present in the string itself. You can play with stuff like: String test = "abcd"; int index = test.IndexOf('b'); String test2 = test.Substring(index); // etc... There are plenty of methods on the string object. There are also static methods in the String class, like for example: String.Compare(string1, string2...) Last but not least, the namespace you are looking for is simply System.
Jean-Christophe Grégoire
-
I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
ipstefan wrote:
I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
int index = myString.IndexOf(" ");
Kristian Sixhoej
-
ipstefan wrote:
I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
int index = myString.IndexOf(" ");
Kristian Sixhoej
-
Yep I thought at that option too earlier and it works... I solved my problem with indexes and substrings. Thanks
You're welcome :)
Kristian Sixhoej
-
So I read a file and that file has like 9k lines. the lines look like this(well it might not fit here, but is on a line only): A:"extatic" A:"extatici" A:"extaticul" A:"extaticului" A:"extaticii" A:"extaticilor" A:"extatică" A:"extatice" A:"extatica" A:"extaticei" A:"extaticele" A:"extaticelor" And I use textreader in c# to find a char in that text for example "extaticele" here. What I want is to extract if I found the char on that line the first char on that line. In this case "extatic" - but without "" of course and paste it in a text file. I dont know exactly how to work with find space so I want your help...cause I thought I'd find the first space in the line then take the index and with the index 0 of the line to extract "A:"extatic" ". Then remove the "A:" and the ". I saw somewhere an example with myString.find("") , but I can't find the "find" I might need a namespace.
hi ipstefan, my sugession is read contents of file sequentially and check whether the character u r reading is ", it it is then take all next characters untill next " apprears so u can get each character between "". From these chars u can make a string by using + operator and later it can be pasted where u want. Or as u mentioned myString.find() method, i hope find method is custom method not in framework. Instead, u can use following method of class String. String myString = "abcd"; String cutString = myString.Substring(0,3); the value of cutString will be 'abc' . Try to use this method. Ok.. Hope it will help u.