ApexSensei

Drills Apex basics

Parse an email

indexOf and substring split an email address into the part before and after the @.

Your task

Split two Contact emails at their own @, then spot an email with no @ without throwing.

String email = 'maya.chen@example.com';
Integer atIndex;
String localPart;
String domain;

// Case A: maya.chen@example.com

// Case B: admin@io.dev
email = 'admin@io.dev';

// Case C: no @ at all
email = 'maya.chen.example.com';

Requirements

  1. substring, substringBefore or substringAfter should be used
  2. First local: maya.chen should be printed
  3. First domain: example.com should be printed
  4. Second local: admin should be printed
  5. Second domain: io.dev should be printed
  6. Third at index: -1 should be printed
  7. Third valid: false should be printed

Sign in to open this drill