How to get the last two characters in string [Resolved]

Posted by Kavi.Sirius under ASP.NET on 5/14/2012 | Points: 10 | Views : 2861 | Status : [Member] | Replies : 3
hi,

string url="D:\Kavi\WebSite3\Test\ET_Seating Management System_URD_V0_pdf.pdf";

in this url string i need to get the last two characters only with the backslash

Test\ET_Seating Management System_URD_V0_pdf.pdf

how can i get

Thanks in advance...

Regards
Kavi.n



Responses

Posted by: Sakthi.Singaravel on: 5/14/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
string url = "D:\Kavi\WebSite3\Test\ET_Seating Management System_URD_V0_pdf.pdf";

string temp_url = Regex.Replace(url, "(.*?)(\\(.[^\\]*?)\\(.[^\\]*?)\.pdf)$", "$2");



Regards,
Singaravel M

Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 5/14/2012 [Member] Silver | Points: 25

Up
0
Down
ur url string must end with .pdf....?

Regards,
Singaravel M

Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/23/2012 [Member] Starter | Points: 25

Up
0
Down
HI,

ASPX PAGE:


<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

CodeBehind="Default.aspx.cs" Inherits="fetchlastcharacter._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
&nbsp;</p>
<p>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</p>
</asp:Content>


ASPX.CS

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace fetchlastcharacter
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{

string retString = null;
retString =TextBox1.Text.Substring(16, 45);
TextBox2.Text = retString;

}
}
}




OUTPUT:

Test\ET_Seating Management System_URD_V0_pdf.pdf


HOPE THIS WILL HELP

REGARDS

sriram

Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response