locked
c# remove certain part of a string RRS feed

  • Question

  • ok i have multiple strings that i get though a file though a foreach loop they are all in this format 

    sndnt#ps_wfoly_plr_sm_mpapa7_reload_empty_xmag_045

    what im trying to do is remove evreything before reload i would be left with 

    reload_empty_xmag_045

    have tried to do following code but is not working as i thought it would work 

    int indexOfSteam = text.IndexOf("reload");
    if (indexOfSteam >= -1)
    text = text.Remove(indexOfSteam);

    and this removes reload_empty_xmag_045

    but i want it to remove to the left not right and cant seem to get this to work any help would be much appreciated

    Wednesday, May 27, 2020 8:57 PM

Answers

  • Hello,

    Before getting into this question, is this question resolved (and if so please mark a reply as answered if one helped) or let us know if you are still having issues: c# how to search inside all files and files inside sub dir for certain string 

    If you keep asking questions like the above and never close them out nobody is going to want to help you.

    Any ways

    var simulatedLines = new List<string>()
    {
        "sndnt#ps_wfoly_plr_sm_mpapa7_load_empty_xmag_045",
        "sndnt#ps_wfoly_plr_sm_mpapa7_reload_empty_xmag_045",
        "sndnt#ps_wfoly_plr_sm_mpapa7_relempty_xmag_045"
    };
    
    foreach (var line in simulatedLines)
    {
        if (line.Contains("reload"))
        {
            var pos = line.IndexOf("reload");
            var result = line.Substring( pos);
            Console.WriteLine(result);
        } 
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, May 27, 2020 9:34 PM

All replies

  • Hello,

    Before getting into this question, is this question resolved (and if so please mark a reply as answered if one helped) or let us know if you are still having issues: c# how to search inside all files and files inside sub dir for certain string 

    If you keep asking questions like the above and never close them out nobody is going to want to help you.

    Any ways

    var simulatedLines = new List<string>()
    {
        "sndnt#ps_wfoly_plr_sm_mpapa7_load_empty_xmag_045",
        "sndnt#ps_wfoly_plr_sm_mpapa7_reload_empty_xmag_045",
        "sndnt#ps_wfoly_plr_sm_mpapa7_relempty_xmag_045"
    };
    
    foreach (var line in simulatedLines)
    {
        if (line.Contains("reload"))
        {
            var pos = line.IndexOf("reload");
            var result = line.Substring( pos);
            Console.WriteLine(result);
        } 
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, May 27, 2020 9:34 PM
  • Hello,

    Before getting into this question, is this question resolved (and if so please mark a reply as answered if one helped) or let us know if you are still having issues: c# how to search inside all files and files inside sub dir for certain string 

    If you keep asking questions like the above and never close them out nobody is going to want to help you.

    Any ways

    var simulatedLines = new List<string>()
    {
        "sndnt#ps_wfoly_plr_sm_mpapa7_load_empty_xmag_045",
        "sndnt#ps_wfoly_plr_sm_mpapa7_reload_empty_xmag_045",
        "sndnt#ps_wfoly_plr_sm_mpapa7_relempty_xmag_045"
    };
    
    foreach (var line in simulatedLines)
    {
        if (line.Contains("reload"))
        {
            var pos = line.IndexOf("reload");
            var result = line.Substring( pos);
            Console.WriteLine(result);
        } 
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thank you for fast replay and this has resolved the issue marked as answer sorry about confusion before.
    Wednesday, May 27, 2020 9:55 PM