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
Answers:
Write "n"
as raw string
:
cardText = rawCardText.replace(r'n', '+ "n" +')
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
Write "n"
as raw string
:
cardText = rawCardText.replace(r'n', '+ "n" +')