• shubham sharma 200
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
// Map to keep key (caregory) and value related to each other
        Map<String, String> mailValues = new Map<String, String>();
        
        // Seperate keys and values and put it in the map 
       	List<String> listOfLines = plainText.split('\n');
        for(String line : listOfLines){
            String key   = line.substringBetween('<', '>');
            String value = line.substringBetween('<' + key + '>', '</' + key + '>');
            
            if (key != null) {                                    // this works just fine, null key not added 

            // if (key != null || value != null){           // works partial, null key not added, but empty value added
            //  if (key != null || value != ''){              // doesn't work at all, null key + empty value get added 

                mailValues.put(key, value);                
            }
Hi guys, I'm getting tagged values per mail in this format:

<key>value</key>
<key2>value</key2>

Somethimes there are linebreaks, so I get a null key added to the map. Got that solved with "key != null".

But I'm struggling with excluding no-values like <key></key>.
Probably easy, but I'm absulte beginner … can someone give me a hand here?