I am in dire need of help with a solution

ivanbossa

New member
Joined
Apr 11, 2022
Messages
4
Programming Experience
Beginner
Convert the text from a text file by replacing each letter of the Latin alphabet with the symmetrical one from the alphabet. Ex: (a <-> z, b <-> y, c <-> x …….). Save the result in a new text file.

I would be really grateful!
 
This is not a place to get others to do your homework for you. You need to do the work and, if you encounter a specific issue, ask a specific question about that. Your post should contain a FULL and CLEAR explanation of the problem, including what you're trying to achieve, how you're trying to achieve it and what happens when you try, then the title should be a summary of the issue. Your title is as much use as no title at all and your post doesn't indicate that you have made any effort at all on your own behalf.

You should start trying to solve any programming problem by forgetting that it's a programming problem. Work out the logic first, then write code to implement that logic. If you had to do this task manually, how would you do it? I bet you'd have little problem doing it so you know how to do it. Write that down. Break it up into smaller and smaller steps and formalise those steps until you have an algorithm, then write code to specifically implement that algorithm. If you come here with a question, you should be able to point to the specific step in that algorithm that you're having trouble implementing.
 
This is not a place to get others to do your homework for you. You need to do the work and, if you encounter a specific issue, ask a specific question about that. Your post should contain a FULL and CLEAR explanation of the problem, including what you're trying to achieve, how you're trying to achieve it and what happens when you try, then the title should be a summary of the issue. Your title is as much use as no title at all and your post doesn't indicate that you have made any effort at all on your own behalf.

You should start trying to solve any programming problem by forgetting that it's a programming problem. Work out the logic first, then write code to implement that logic. If you had to do this task manually, how would you do it? I bet you'd have little problem doing it so you know how to do it. Write that down. Break it up into smaller and smaller steps and formalise those steps until you have an algorithm, then write code to specifically implement that algorithm. If you come here with a question, you should be able to point to the specific step in that algorithm that you're having trouble implementing.
The problem is, I managed to replace each letter of the Latin alphabet with the symmetrical one from the alphabet but I have to manually enter my input in the code. I really don't understand how to work with text files inside my code. I can't find out how to use a text file and what is inside it as an input and save the output in a new text file.
This is the code I used to replace the letters.
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApp8
{
    class GFG
    {


        static void Reciprcalstring(string word)
        {
            char ch;
            for (int i = 0; i < word.Length; i++)
            {
                ch = word;
                if (Char.IsLetter(ch) && ch < 128)
                {

                    // converting lowercase character to the opposite character

                    if (char.IsLower(ch))
                    {
                        ch = (char)(122 - (int)(ch) + 97);
                    }

                    //  for uppercase letters

                    else if (char.IsUpper(ch))
                    {
                        ch = (char)(90 - (int)(ch) + 65);
                    }
                }

                // display each character
                Console.Write(ch);
            }
        }


        // Driver function
        public static void Main()
        {
            string s = "Example text";
            Console.Write("The reciprocal of " + s +
                          " is - " + "\n");

            // calling the function
            Reciprcalstring(s);
        }
    }
 
Last edited by a moderator:
It is not my intention to discourage people using this site and others like it but I do want to encourage people to do what they can for themselves first. If you want to read a text file in C# and don't know how, the first thing to do is search the web for "c# read text file" or the like. There's LOADS of information already out there on such a common subject. It would take a few minutes at the most to learn how. There are a number of different specific options so I'll give you a freebie this time: File.ReadAllText.
 
I don't think that at all. To be frank, I think that anyone who actually looked would find loads of information very quickly. I just searched for the keywords I included in my previous post and, while the first result was specifically for reading line by line, the second result had multiple code examples, the very first of which demonstrates the use of File.ReadAllText. That's probably less than a minute to find a relevant example. I really do wonder sometimes what people actually type into a search engine, that I can find information so quickly and they can't after apparently searching for an eternity. Being able to find information is critical for any developer so, if you can't use a search engine effectively, you're going to struggle.
 
I don't think that at all. To be frank, I think that anyone who actually looked would find loads of information very quickly. I just searched for the keywords I included in my previous post and, while the first result was specifically for reading line by line, the second result had multiple code examples, the very first of which demonstrates the use of `File.ReadAllText`. That's probably less than a minute to find a relevant example. I really do wonder sometimes what people actually type into a search engine, that I can find information so quickly and they can't after apparently searching for an eternity. Being able to find information is critical for any developer so, if you can't use a search engine effectively, you're going to struggle.
Okay, time to tell the truth. I find developing really hard. Yes I have spend most of my time, researching File.ReadAllText and StreamReader (that's how I ended up in your forum, from a similar thread). My Google Search History is full of searches for this specific problem which I have been trying to solve for days. When I insert:
StreamReader sr = new StreamReader(@"C:\Users\PC HOME\Documents\Za saita\input.txt"); (or try with File.ReadAllText)) When finalize everything, it tells me that ''Program does not contain a static 'Main' method suitable for an entry point''.
 
When I insert:
StreamReader sr = new StreamReader(@"C:\Users\PC HOME\Documents\Za saita\input.txt"); (or try with File.ReadAllText)) When finalize everything, it tells me that ''Program does not contain a static 'Main' method suitable for an entry point''.
That error message has got nothing to do with that code. You should work out how to actually run a Console app project before trying to do anything in one, which would generally mean a simple Hello World app. I'm not going to go off into the weeds in this thread. If you have another issue then you can create another thread and we can deal with it there, then you can come back to this thread if needs be.
 
Sounds like you have place code outside the code block and broken the main() entry point, either place the code in the int main() block or make a new function to load said text file,


Example:
//add string variable to just under int main() so you can get it globally
string StringfromTextfile = null;
//Pathtotextfile is out string so we can call anypath to any textfile needed
void LoadingTextFile(string Pathtotextfile)
{   
    //Set the location to Pathtotextfile
    StreamReader sr = new StreamReader(Pathtotextfile);
    StringfromTextfile = sr.ReadToEnd();
    sr.Close();
}

this is just a rough guide, you can search / read more in to it, also adding if file exsists and a try / catch would be good practice too for file handling.

Hope this helps.

ProtekNickz :)
 
Um... He could have read the text file with a one liner:
C#:
var text = File.ReadAllText(fileName);
 
Back
Top Bottom