.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 >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How To Split Last String

Posted By: Jayakumar     Posted Date: September 07, 2010    Points:2   Category :ASP.Net
i need How To Split Last String

"http:\\www.microsoft.com"

i need like this using the command lastindexof
microsoft.com

Responses
Author: Majith             
Posted Date: September 07, 2010     Points: 5   

Hi JayaKumar,

In C# string handling methods the lastIndexOf method is used to find the last occurrence of a character or string.This method includes various over loaded options to locate the strings of last position.

The method finds the string from the last character to the first character. If the value is located, its index is returned or -1 is returned.


string strTest = "http:\\www.microsoft.com";
int index= strTest.LastIndexOf('\');
if(index= == -1)
{
// Do the operation
}
int index1= strTest.LastIndexOf("com");


Thanks

Author: Akhil Raj       [Moderator]      
Posted Date: September 07, 2010     Points: 5   

you can use the followign options to find 'microsoft.com'

1. Using IndexOf

string str = "@http:\\www.microsoft.com";
String answer = str.Substring((str.IndexOf('.') + 1), str.Length - (str.IndexOf('.') + 1));

2. Using Split method

string str = "@http:\\www.microsoft.com";
String answer = str.Split('.')[1] + "." + str.Split('.')[2];

LastIndex is some complex because you not pick the last part after dot.

Author: Asha.MP             
Posted Date: September 09, 2010     Points: 5   

Dim StrToSplit As String = "http://www.microsoft.com"
Dim StrSplit As String = StrToSplit.Substring(StrToSplit.IndexOf("microsoft.com"))

StrToSplit.IndexOf("microsoft.com")-->Return the index of "microsoft.com"
StrToSplit.Substring(StrToSplit.IndexOf("microsoft.com"))-->Split the string by that index


Thanks and Regards,
Asha.mp


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