-3
string ABC = "This is test AZ12346";

Need value that occurs after AZ. AZ will always be present in the string and it will always be the last word. But number of characters after AZ will vary.

Output should be : AZ123456

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
bHaRaTh N
  • 1
  • 1
  • 8
  • And what have you tried? This could be very simple with both RegEx and indexOf + substring – Camilo Terevinto Feb 01 '19 at 14:30
  • 2
    _"Need value that occurs after AZ"_ .... _"Output should be : AZ123456"_ – Tim Schmelter Feb 01 '19 at 14:31
  • `ABC.Split(new [] { "AZ" }, StringSplitOptions.Remove)[1]` ^_^ – Icepickle Feb 01 '19 at 14:32
  • Welcome to Stack Overflow! Please take the [tour], and familiarize yourself with [ask] (preferably with a [mcve]). Your question as it is now will likely receive down-votes due to an apparent [lack of effort](http://idownvotedbecau.se/noattempt) and what seems to be contradictions in your question. –  Feb 01 '19 at 14:32

2 Answers2

0

You can try LastIndexOf and Substring:

string ABC = "This is test AZ12346";
string delimiter = "AZ";

// "AZ123456"
string result = ABC.Substring(ABC.LastIndexOf(delimiter));

In case delimiter can be abscent

int p = ABC.LastIndexOf(delimiter);

string result = p >= 0
  ? ABC.Substring(p)
  : result; // No delimiter found  

If you are looking for whole word which starts from AZ (e.g. "AZ123", but not "123DCAZDE456" - AZ in the middle of the word) you can try regular expressions

 var result = Regex
   .Match(ABC, @"\bAZ[A-Za-z0-9]+\b", RegexOptions.RightToLeft)
   .Value;
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

Simply :

ABC.Substring(ABC.LastIndexOf("AZ")); 
Navid Rsh
  • 308
  • 1
  • 6
  • 14