How to replace all instances of "n" in a string with linebreaks

Question:

I am using data scraped from a website and making my bot display in separate lines. There is a particular string whose information has “n” in between and I want to convert those into actual line breaks

I have tried replacing the ‘n’ with ‘+ “n” +’ but the output is still the same

This is an example of the issue I have, and not the actual bot code

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

Client = discord.Client()
client = commands.Bot(command_prefix = "!")

cardName = "Card Name"
rawCardText = "This is an abilitynThis is another ability"
cardText = rawCardText.replace('n', '+ "n" +')

fullText = cardName + "n" + cardText
await client.send_message (message.channel, fullText)

I expected something like this:

Card Name

This is an ability

This is another ability

Instead what I get is:

Card Name

This is an abilitynThis is another ability

Asked By: SaltyHelpVampire

||

Answers:

Write "n" as raw string:

cardText = rawCardText.replace(r'n', '+ "n" +')
Answered By: Taohidul Islam
cardName = "Card Name"
rawCardText = "This is an abilitynThis is another ability"
cardText = rawCardText.split('n')
fullText = fullText = (cardName + 'n' + 'n'.join(cardText))
print (fullText)

enter image description here

Answered By: anand_v.singh
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.