badb0nny
badb0nny
CC#
Created by badb0nny on 12/22/2022 in #help
✅ Probably a simple general knowledge question, not to sure what to title it?
Im trying to store some data in a seperate file and then use it in a string but for some reason the string seems to come out as 2 strings which split at the variable?
string data = File.ReadAllText("./ntfFuoyFGA7qts1i/MDBP.txt");
string MDBLink = String.Format("hello {0}", data);
string data = File.ReadAllText("./ntfFuoyFGA7qts1i/MDBP.txt");
string MDBLink = String.Format("hello {0}", data);
for some reason returns hello /data/ and im trying to make it return hello /data/
2 replies
CC#
Created by badb0nny on 12/6/2022 in #help
❔ trying to encode and decode a user inputted string
Im struggling to figure out why it doesnt decode back into the original string?
using System;

namespace Encode_Decode_Program
{
class Globals
{
public static string encodeDecodeKey;
public static int encodeInteger;
public static string encodedString;
public static string decodedString;
}

class Program
{
static void Main()
{
Random rnd = new Random();
Console.WriteLine("Enter a string which you want decoded: "); string encodeString = Console.ReadLine();

for (int x = 0; x < encodeString.Length; x++)
{
int asciiValue = encodeString[x];
Globals.encodeInteger = rnd.Next(1, 9);
Globals.encodeDecodeKey = Globals.encodeDecodeKey + Globals.encodeInteger;
char encodedCharacter = (char)(asciiValue + Globals.encodeInteger);
Console.WriteLine(Globals.encodeDecodeKey);
Console.WriteLine(encodedCharacter);
Globals.encodedString = Globals.encodedString + encodedCharacter;
}

for (int x = 0; x < Globals.encodedString.Length; x++)
{
int asciiValue = Globals.encodedString[x];
char decodedCharacter = (char)(asciiValue - Globals.encodeDecodeKey[x]);
Console.WriteLine(decodedCharacter);
Globals.decodedString = Globals.decodedString + decodedCharacter;
}

Console.WriteLine("Encoded string: " + Globals.encodedString);
Console.WriteLine("Decoded string: " + Globals.decodedString);
Console.ReadLine();
}
}
}
using System;

namespace Encode_Decode_Program
{
class Globals
{
public static string encodeDecodeKey;
public static int encodeInteger;
public static string encodedString;
public static string decodedString;
}

class Program
{
static void Main()
{
Random rnd = new Random();
Console.WriteLine("Enter a string which you want decoded: "); string encodeString = Console.ReadLine();

for (int x = 0; x < encodeString.Length; x++)
{
int asciiValue = encodeString[x];
Globals.encodeInteger = rnd.Next(1, 9);
Globals.encodeDecodeKey = Globals.encodeDecodeKey + Globals.encodeInteger;
char encodedCharacter = (char)(asciiValue + Globals.encodeInteger);
Console.WriteLine(Globals.encodeDecodeKey);
Console.WriteLine(encodedCharacter);
Globals.encodedString = Globals.encodedString + encodedCharacter;
}

for (int x = 0; x < Globals.encodedString.Length; x++)
{
int asciiValue = Globals.encodedString[x];
char decodedCharacter = (char)(asciiValue - Globals.encodeDecodeKey[x]);
Console.WriteLine(decodedCharacter);
Globals.decodedString = Globals.decodedString + decodedCharacter;
}

Console.WriteLine("Encoded string: " + Globals.encodedString);
Console.WriteLine("Decoded string: " + Globals.decodedString);
Console.ReadLine();
}
}
}
I know its not the neatest code of all time im still trying to get into the habit of writing neat code
4 replies
CC#
Created by badb0nny on 11/30/2022 in #help
❔ Reading data from a text file
I have only just started trying to work with txt files and was wondering if anyone could help me and try to fix my code! string fileName = "Cookies.txt"; TextWriter textFileWrite = new StreamWriter(fileName); TextReader textFileRead = new StreamReader(fileName); string data; if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) == null) { Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine(); textFileWrite.WriteLine(choice); } if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) != null) { Console.WriteLine("You selected: " + data); Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine(); textFileWrite.WriteLine(choice); } textFileRead.Close(); textFileWrite.Close();
11 replies