|
Forums » .NET » .NET »
|
Split the string and stored in to array |
Posted Date: 10 Aug 2012 Posted By:: Gopi A Member Level: Silver Member Rank: 349 Points: 5
Responses:
9
|
Hi Friends,
I want to split the string after read from INI file. Below is my code.
I have read the line from INI file that which contain the keyword "ABC" at the starting position. Here i want to read the element of ABC that "i,a,s". I can able to read this but the first value shows along with the keyword "ABC". I don't want this. I need only the values. Could anyone help me.
string line; string charname = string.Empty; StreamReader file = new
System.IO.StreamReader(@"H:\Dotnet Practice\INI\INI\bin\Debug\emp.ini"); { while ((line = file.ReadLine()) != null) { if (line.StartsWith("ABC")) { //string[] fullName = line.Split('='); // charname = fullName[1];
string[] splitcharname = line.Split(',');
foreach (string splitchar in splitcharname ) { MessageBox.Show(splitchar);
// if (splitchar == textBox1.Text) // { // MessageBox.Show("not allowed"); // } //break; } } }
INI file input:
ABC=i,a,s
output should be:
i a s
Please help me
Regards, Gopi A
----------------------------------------------------------------------------- Regards, Gopi A. +91 9894315571 Skype:gopi.net
|
Responses
|
#683940 Author: Prasad kulkarni Member Level: Diamond Member Rank: 8 Date: 11/Aug/2012 Rating:  Points: 3 | Let's chnage your program flow. after ytou have identified the line start's with ABC then you can remove it from string get only remaining string or you can split code with "=" and get ramining part.
check following example
while ((line = file.ReadLine()) != null) { if (line.StartsWith("ABC")) { string[] splitcharname = line.Split('=')[1].Split(',');
foreach (string splitchar in splitcharname ) { MessageBox.Show(splitchar); } }
hope it helps
Thanks Koolprasd2003 [DotNetSpider MVM]
| #683947 Author: Ajatshatru Upadhyay Member Level: Gold Member Rank: 19 Date: 11/Aug/2012 Rating:  Points: 3 | Hi,
Check out the following code snippet:
while ((line = file.ReadLine()) != null) { if (line.StartsWith("ABC")) { string[]splitcharname = line.Substring(line.IndexOf('=') + 1).Split(','); foreach (string splitchar in splitcharname) { MessageBox.Show(splitchar); } } }
Hope it'll help you. Regards Ajatshatru
| #683974 Author: Gopi A Member Level: Silver Member Rank: 349 Date: 11/Aug/2012 Rating:  Points: 1 | Hi,
Thanks for your help. Both has been work.
Regards, Gopi A
----------------------------------------------------------------------------- Regards, Gopi A. +91 9894315571 Skype:gopi.net
| #684314 Author: Gopi A Member Level: Silver Member Rank: 349 Date: 15/Aug/2012 Rating:  Points: 1 | Hi,
Whatever i put the letters under the "ABC" keyword should not allow in textbox while entering in textbox.
How can we do this.
Regards, Gopi A
----------------------------------------------------------------------------- Regards, Gopi A. +91 9894315571 Skype:gopi.net
| #684337 Author: Ajatshatru Upadhyay Member Level: Gold Member Rank: 19 Date: 15/Aug/2012 Rating:  Points: 1 | Hi,
I did not get you. Would request you to explain in again
Hope it'll help you. Regards Ajatshatru
| #684351 Author: Gopi A Member Level: Silver Member Rank: 349 Date: 15/Aug/2012 Rating:  Points: 1 | Hi,
I want to prevent some characters, special characters, symbols in textbox while keying at run time. Here i am using INI file (refer the above thread). In INI file there is some keyword like "ABC".
ABC= #,%,[
Here i do not want to key the above symbols in textbox (this is not constraint, it will be change).
Regards, Gopi A
----------------------------------------------------------------------------- Regards, Gopi A. +91 9894315571 Skype:gopi.net
| #684377 Author: Ajatshatru Upadhyay Member Level: Gold Member Rank: 19 Date: 15/Aug/2012 Rating:  Points: 2 | You want something like this?
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { string sp_char = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; for (int key = 0; key < sp_char.Length; key++) { if (e.KeyChar == sp_char[key]) { MessageBox.Show("Special characters are not allowed!!!"); e.Handled = true; } } }
Hope it'll help you. Regards Ajatshatru
| #684382 Author: Gopi A Member Level: Silver Member Rank: 349 Date: 15/Aug/2012 Rating:  Points: 1 | Hi,
Thanks for the help, It's working fine.
Regards, Gopi A
----------------------------------------------------------------------------- Regards, Gopi A. +91 9894315571 Skype:gopi.net
|
|
| Post Reply |
|
|
|
You must Sign In to post a response.
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|