-1
\$\begingroup\$

Getting some JSON with a string link to images(on the server) and want to save them on device.
To save them I have to name them, so the name of the file on the server would be perfect.
Example: I have this link https://pbs.twimg.com/profile_images/882558757531791360/CGKUrcD9.jpg
How can I get CGKUrcD9.jpg part of it using C# and Unity?

\$\endgroup\$
1
  • 2
    \$\begingroup\$ This is a basic question about parsing strings in C#. Programming questions which aren't specific to game development should be posted on stackoverflow.com... if they are not already posted and answered. \$\endgroup\$
    – Philipp
    Commented Jan 17, 2018 at 16:31

1 Answer 1

1
\$\begingroup\$

Use LastIndexOf to get the position of the last antislash and use Substring to "cut" your string after the antislash:

string GetFileName(string link)
{
    return link.Substring( link.LastIndexOf('/') + 1 ) ;
}
\$\endgroup\$
1

Not the answer you're looking for? Browse other questions tagged .