I got assignment to do first line in upper case and in the rest every word that is 3 or more characters long starts with upper case.
I am testing it in console so its made partly with streamreader/streamwriter, but when it functions well I will correct it.
Problem is that the Console.WriteLine(); before for loop with it, it makes an empty line after the first line but without it, it does not make 3rd line. The input text looks like this
title of text
sssssss ss ssss, ss sssssss
ddddd ddd ddddd dddddd
with the WriteLine it ends up like this:
TITLE OF TEXT
sssssss ss ssss, ss sssssss
ddddd ddd ddddd dddddd
and without:
TITLE OF TEXT
Sssssss ss Ssss, ss Sssssss Ddddd Ddd Ddddd Dddddd
I think I made it too complicated and got kinda lost so I am looking for the solution to this small problem or also to make this code easier but thats not the point right now.
using System;
using System.IO;
namespace priklad_8._4
{
class Program
{
static void Main(string[] args)
{
firstUpper(@"aaa.txt", @"new.txt");
Console.ReadLine();
}
static void firstUpper(String from, String to)
{
StreamReader sr = new StreamReader(from);
StreamWriter sw = new StreamWriter(to);
String s;
int length = 0;
char[] pole = new char[100];
char dd = 'A';
while ((s = sr.ReadLine()) != null)
{
if (length == 0)
{
Console.WriteLine(s.ToUpper());
length++;
}
else
{
String[] ss = s.Trim(' ').Split(' ');
Console.WriteLine();
for (int i = 0; i < ss.Length; i++)
{
if (ss[i].Length >= 3)
{
String ds = ss[i];
char[] das = ds.ToCharArray();
Console.Write(Char.ToUpper(das[0]) + ds.Substring(1) + " ");
if ((int)dd == 10)
{
Console.WriteLine();
}
}
else Console.Write(ss[i] + " ");
}
}
}
sw.Close();
sr.Close();
}
}
}
Thank you!
If you want to leave everything else as it is, just instead of
Console.WriteLine(s.ToUpper());
use this:
Console.Write(s.ToUpper())