.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

How to Split 'abc123'

Posted By: Syed Shakeer Hussain     Posted Date: August 23, 2009    Points:2   Category :C#
Suppose i have a string str="abc123";
i want to split this string into two parts as
String str1="abc"
int i=123

Responses
Author: Praveen             
Posted Date: August 24, 2009     Points: 5   

Hello,
Its tricky question...to check the numeric value from a given string well here is the solution i tried..there may be so many ways


string str = "abc123";

string iResultTemp = string.Empty;
string sCurrentVal = string.Empty;
string sResult = string.Empty;
for (int i = 0; i < str.Length; i++)
{
try
{
sCurrentVal = str.Substring(i, 1);
if(IsNumeric(sCurrentVal))
{
iResultTemp += sCurrentVal;
}
else
{
sResult += str.Substring(i, 1);
}

}
catch
{
// Catch Exception
}

}

int iFinalResult = int.Parse(iResultTemp);
string sFinalResult = sResult;


This method is used to check that given string in numeric value or not

public bool IsNumeric(string s)
{
try
{
Int32.Parse(s);
}
catch
{
return false;
}
return true;
}




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend