Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

IO.readlines question (how do I get rid of \n?)

Status
Not open for further replies.

OS

Sponsor

Hello, again^2. I am using IO.readlines to create an array of strings to use in my code. Unfortunately, each string has an invisible \n I can't seem to get rid of...

If someone can explain to me how I would go about doing this, I would be so greatful.

Peace!

Edit:
Here is the line of code I am using, in case that helps.
Code:
@text = IO.readlines("Data/Interact Data/#{type}/#{@file}")
type is the next folder, and file is the file...

Peace!^2
 
Maybe trying gsub(/Text you want to check/) {|s| "What should e put instead" }

Just use like this : @string = "asdbbbb"

@string.gsub(/b/) {|s| "" } # returns @string = "asd"
 

OS

Sponsor

Thanks! It works now, except...I am testing this by using the print statement, and the last value printed (which is also the last String) is missing the last letter...

I could just add a blank space at the end of each document, I guess, but is there any way to stop the last letter in the last string from deleting?

Peace!
 
This topic has been resolved. If OptimistShadow or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top