locked
C# To Take A Portion of Filename RRS feed

  • Question

  • User-1861919626 posted

    I have a C# ASP.Net app that once the user clicks the submit button, it is saving the record in this syntax "FirstName_LastName_TodaysDate" so for example my data for today would be Mitch_Smith_09092013.  The snare I am hitting is that if another user needs to modify any info in my record when they click submit (or even the save button) it is appending the date to the record, so for example the name of the record would then be Mitch_Smith_09092013_09092013.

     

    How can I set it to remove the right 8 characters when the record is opened?  I am sure it is something using substring & right combination, but my ASP/C# skills are very new...

    Monday, September 9, 2013 1:17 PM

Answers

  • User533502567 posted

    How can I set it to remove the right 8 characters when the record is opened?  I am sure it is something using substring & right combination, but my ASP/C# skills are very new...

    Something like this..

    strTemp = strTemp.Remove(str.Length - 8);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2013 1:20 PM

All replies

  • User533502567 posted

    How can I set it to remove the right 8 characters when the record is opened?  I am sure it is something using substring & right combination, but my ASP/C# skills are very new...

    Something like this..

    strTemp = strTemp.Remove(str.Length - 8);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2013 1:20 PM
  • User551462331 posted

    for this scenario, u can use string method available in framework

    strName = strName.SubString(0,strName.LastIndexOf("_")-1);

    hope this helps...

    Monday, September 9, 2013 1:23 PM
  • User1508394307 posted

    a small correction, - SubString must be written as Substring which is important in c#

    http://msdn.microsoft.com/en-us/library/vstudio/aka44szs.aspx

    string str = "Mitch_Smith_09092013";
    str = str.Substring(0, str.Length - 8);

    Monday, September 9, 2013 1:54 PM