Home > Back-end >  How to extract a word from a link?
How to extract a word from a link?

Time:07-08

Faced a problem. I get a link and I need to extract a password-reset, how can I do this? For example, to get code I use queryParameters['code'], but how do I extract the word password-reset from the link, I need this text for navigation?

link

https://test.test.test.test/app/password-reset?code=6294

need to get

password-reset

CodePudding user response:

Use substring, the code will extract the text between the last / and the first ?:

var link = "https://test.test.test.test/app/password-reset?code=6294";

var start = link.lastIndexOf('/')   1;
var end = link.indexOf('?');

var extract = link.substring(start,end);

print(extract);

CodePudding user response:

If you have the same link, and know the index position of the letters.This would be helpful for you.

String myLink = 'https://test.test.test.test/app/password-reset?code=6294';
String wantedString = myLink.substring(32,46);
  • Related