skip to Main Content

I have shared the relevant image below.

enter image description here

Text in image ;

"C:UsersHpOneDrive-blablablablaMasaustuEdaGorsel4.PNGtmanagertmanagert2022/12/12rndddtV1.0"

  1. I only want 4.PNG from the above post

2.I should not use special names or filenames

3.Ex: t between like this

I hope I was able to explain my problem

3

Answers


  1. you could use a Regex match to get this part of the url :

    private Regex _regex = new Regex(@"^.*\(?<Image>.*.PNG)\.*$");
    

    (You can test regex here)

    Then use this to read the match :

    var result = _regex.Match(url).Groups["Image"].Value;
    

    Another, simplier solution, would be to use :

    url.Split("\")[6];
    

    This works only if the searched part is always at the same spot.

    Login or Signup to reply.
  2. there is sevral ways

    1. if you know number of "" in your string then split it(str.Split(‘ ‘)) and get wanted index

    2. use regular expersion to extract filename

    Login or Signup to reply.
  3. You can split your strings into many shorter ones using .Split function:

    string[] words = path.Split("\");
    

    Using the double to escape the character..

    If you don’t guarantee that the string you need is always at the same position, you can use this to fetch it from the list:

    string neededString = words .FirstOrDefault(str => str.Contains(".PNG"));
    

    This will return the first instance of any word from your string that contains ".png" in it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search