Making a Multi Line String into a Single Line

Hi,
I have a string that is multiple lines, but I need it to be a single line!
What the string is supposed to be:

Character: Brylan2  - 

What the string is:

	Character: 
	Brylan2  -

What should I do to make this into a single line?

You haven’t provided any code.

Could you elaborate a little further? Is this a string assigned to a variable? Is it an input from somewhere that is line separated?

I’m using an AI to create lines for characters, here’s the ai response in that instance:

-- START OF SCRIPT -- |
12|
Brylan2: Hey guys, what's up? |
mightycolaa: Not much, just chilling. |
pufflecats: Same here. |
FoxBin: Yeah, me too. |
TheRealLegendaryAura: What do you guys want to do today? |
TheMasterKnight1: I'm up for anything. |
LeDrTroll: Me too. |
6ZT2: Let's go to the movies. |
Ethanlovir: That's a good idea. |
Mertired: I'm down. |
Brylan2: Alright, let's do it. |
pl_w: Sounds good to me. |
-- END OF SCRIPT --  

Here’s the code for converting the ai response:

local response = RequestResponse()

if typeof(response) == "string" then
	print("Full Response: "..response)
	local split = string.split(response, "|")
	local amount = split[2]
	print("Dialog Amount: "..amount)
	for i = 0, amount-1 do
		print("Dialog "..(i+1)..": "..split[i+3])
		local dialog = string.split(split[i+3], ":")
		print("Character: "..dialog[1])
		print("Text: "..dialog[2])
		if workspace.Chars:FindFirstChild(dialog[1]) then
			ChatService:Chat(workspace.Chars:FindFirstChild(dialog[1]):FindFirstChild("Head"),dialog[2])
			task.wait(string.len(dialog[2])/2)
		else
			print("character not found!")
		end
	end
else
	error("somehow its not a string and i dont know why")
end

You would basically want to remove all of the new line characters. Let me try testing out some methods and I’ll get right back to you

1 Like

Okay try this out and use responseSingleString:

local response = RequestResponse()
local responseSingleString = string.gsub(response, "\n", " ")

Unsure of how you wanna do your type checking so you can play with this as you need and change when the conversion happens. Lmk if this works out for you

2 Likes

Works perfectly, found the best results when doing local response = string.gsub(multilineresponse, "\n", "")
Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.