dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersSarfaraz M Bhat
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




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: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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: 2 out of 52 out of 5     Points: 1

Hi,

Thanks for your help. Both has been work.

Regards,
Gopi A

-----------------------------------------------------------------------------
Regards,
Gopi A.
+91 9894315571
Skype:gopi.net






 
#684028    Author: Ajesh Madhukar Dalvi      Member Level: Silver      Member Rank: 340     Date: 12/Aug/2012   Rating: 2 out of 52 out of 5     Points: -1

[Response removed by Admin for invalid response to the thread or violation of forum policies.]


 
#684314    Author: Gopi A      Member Level: Silver      Member Rank: 349     Date: 15/Aug/2012   Rating: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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.

Next : What is n-unit testing? how to it works?
Previous : Problem in saving vb.net to mysql
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.