1

I want to save very large text in a variable (SPACE INVADERS), How can I save that type of text in a variable? . I'm learning c # I need help please.

Code: ---------------------------------------------------------------------------------------------------------------------------

namespace SpaceInvaders2017
{
    class Program
    {
        struct AtribEnemigos {
            public string simbolo;
            public ConsoleColor color;
            public bool visible;
            public int posColInicial;
            public int posFilaInicial;
            public float x, y;

        }
        static int nombre;
        static AtribEnemigos Texto;
        public static void MenuJuego(){     
            Console.Clear();
            MoverNombreJuego();
        }
        public static void MoverNombreJuego()
        {
            Texto.color = ConsoleColor.DarkRed;
            Texto.posColInicial = 0;
            Texto.posFilaInicial = 0;
            Texto.x = Texto.posColInicial;
            Texto.y = Texto.posFilaInicial;
 //Error here------------------------
            Texto.simbolo = { "▄▀▀ █▀▄ ▄▀▄ ▄▀▀ █▀▀ . ▀█▀ █▄░█ █░░░█ ▄▀▄ █▀▄ █▀▀ █▀▄ ▄▀▀ ",
                              "░▀▄ █▀░ █▄█ █░░ █▀▀ . ░█░ █▀██ ░█░█░ █▄█ █░█  █▀▀ █▀▄ ░▀▄ ",
                              "▀▀░ ▀░░ ▀░▀ ░▀▀ ▀▀▀ . ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀ ▀▀░ ▀▀▀ ▀░▀ ▀▀░"};
        }

        public static void PausaFotograma()
        {
            Thread.Sleep(40);
        }
        static void Main(string[] args)
        {
            MenuJuego();
            //Console.ReadKey();
            PausaFotograma();
        }
    }
}

Image with errors

1
  • you mean multi-line text? put an @ before the string double quote opening Commented Mar 18, 2017 at 23:12

2 Answers 2

2

You can use the project resources in order to store texts.

  • Right click the project in the Solution Explorer and click "Properties".
  • Select the tab "Resources".
  • In the strings section enter a name for the resource and a value. (Increase the row height and column width for large texts).
  • Close the project properties.

enter image description here

Now you can write:

Texto.simbolo = Properties.Resources.SpaceInvadersTitle;

You will see that Visual Studio lists SpaceInvadersTitle in intellisense.

Sign up to request clarification or add additional context in comments.

3 Comments

Very interesting, do you have to specify the project name -myProjectName.Properties.Resources.SpaceInvadersTitle, or you can use it without. I was reading this
Great, works well and keeps the code cleaner. Thank you.
@StanleyS: The Properties word is part of the namespace. If you are already in the myProjectName, you can drop it. You could also add a using myProjectName.Properties; instead and then simply write Resources.SpaceInvadersTitle, where Resources is a class with static properties for all the resources.
1

You can use @ for multi-line string:

        Texto.simbolo = 
            @"▄▀▀ █▀▄ ▄▀▄ ▄▀▀ █▀▀ . ▀█▀ █▄░█ █░░░█ ▄▀▄ █▀▄ █▀▀ █▀▄ ▄▀▀ 
░▀▄ █▀░ █▄█ █░░ █▀▀ . ░█░ █▀██ ░█░█░ █▄█ █░█  █▀▀ █▀▄ ░▀▄ 
▀▀░ ▀░░ ▀░▀ ░▀▀ ▀▀▀ . ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀ ▀▀░ ▀▀▀ ▀░▀ ▀▀░";

or join strings with + operator and add new lines explicitly:

Texto.simbolo =
    "▄▀▀ █▀▄ ▄▀▄ ▄▀▀ █▀▀ . ▀█▀ █▄░█ █░░░█ ▄▀▄ █▀▄ █▀▀ █▀▄ ▄▀▀ " + Environment.NewLine +
    "░▀▄ █▀░ █▄█ █░░ █▀▀ . ░█░ █▀██ ░█░█░ █▄█ █░█  █▀▀ █▀▄ ░▀▄ " + Environment.NewLine +
    "▀▀░ ▀░░ ▀░▀ ░▀▀ ▀▀▀ . ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀ ▀▀░ ▀▀▀ ▀░▀ ▀▀░";

2 Comments

Thanks, I run into the two options.
@yvanGarcia You didnt "run into" anything. People took the time shared their expertise with you. Be sure to click the checkmark on the one that works best for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.