skip to Main Content

I have a String like below

  <P><STRONG>Hi Bold</STRONG></P>
  <P><U>Hi Underline</U></P>
  <P><STRONG><EM>Hi Bold Italic</EM></STRONG></P>
  <P><STRONG><FONT color=3D#8080ff>Hi Bold Purple</FONT></STRONG></P>
  <P><IMG style=3D"HEIGHT: 152px; WIDTH: 203px" border=3D0 hspace=3D0 al=
  t=3D"Inline Image with alt" src=3D"cid:/Downloads/axie_generated(1).pn=
  g" width=3D1198 align=3Dbaseline height=3D900></P>
  <P><IMG style=3D"HEIGHT: 183px; WIDTH: 188px" border=3D0 hspace=3D0 al=
  t=3D"" src=3D"cid:/Desktop/potato.gif" width=3D495 align=3Dbaseline he=
  ight=3D497></P>
  <UL>
  <LI>List Item</LI>
  <LI><FONT color=3D#8080ff>List Item Purple</FONT></LI></UL>
  <P><FONT color=3D#000000>Stream <A href=3D"https://open.spotify.com/tr=
  ack/42DD4cLqkprJPih3YxXkAO?si=3Dc68ba6d1617d488d">Forever Rain</A></FO=
  NT></P>

If the line is too long it will break into a new line with =n. How can I remove and join the string back into one line without removing the other wanted = in the String?

I have tried replaceAll('=n', '') which does nothing and I have also tried replaceAll('n', '') which successfully remove the newline but the = is still there. If I proceed with replaceAll('=', '') then it will remove all the = including the ones that I want to keep

This is the output after using replaceAll('=n', '')
enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I have figured out the problem. It was because r is also present in the String. Therefore, using replaceAll('=rn', '') helps me to solve it


  2. That’s strange: I just ran this in a DartPad

    const string =
      '<P><STRONG>Hi Bold</STRONG></P>'
      '<P><U>Hi Underline</U></P>'
      '<P><STRONG><EM>Hi Bold Italic</EM></STRONG></P>'
      '<P><STRONG><FONT color=3D#8080ff>Hi Bold Purple</FONT></STRONG></P>'
      '<P><IMG style=3D"HEIGHT: 152px; WIDTH: 203px" border=3D0 hspace=3D0 al=n'
      't=3D"Inline Image with alt" src=3D"cid:/Downloads/axie_generated(1).pn=n'
      'g" width=3D1198 align=3Dbaseline height=3D900></P>'
      '<P><IMG style=3D"HEIGHT: 183px; WIDTH: 188px" border=3D0 hspace=3D0 al=n'
      't=3D"" src=3D"cid:/Desktop/potato.gif" width=3D495 align=3Dbaseline he=n'
      'ight=3D497></P>'
      '<UL>'
      '<LI>List Item</LI>'
      '<LI><FONT color=3D#8080ff>List Item Purple</FONT></LI></UL>'
      '<P><FONT color=3D#000000>Stream <A href=3D"https://open.spotify.com/tr=n'
      'ack/42DD4cLqkprJPih3YxXkAO?si=3Dc68ba6d1617d488d">Forever Rain</A></FO=n'
      'NT></P>';
    
    void main() {
      print(string.replaceAll('=n', ""));
      runApp(const MyApp());
    }
    

    and the output looks just as imagined, with no ‘=’ or ‘n’

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search