C
C#8mo ago
TheOne1984

❔ ✅ :white_check_mark: Trying to have a program read a word in a string and add to a counter

I have to make a program that reads the different letters, consonants and some words as repeated through out the text. I have been able to do it for vowels and consonants, but I do not know what to do for complete specific words in the text.
310 Replies
Sweerpotato
Sweerpotato8mo ago
Can you provide more context? Like what you're trying, what you're expected to output
TheOne1984
TheOne19848mo ago
Yes, basically I have to make a program that reads how many times a letter or a word is repeted in a text, a.k.a. a string. My issue is that I dont know how to make it read a full word such as "Hello". So far it counts letter by letter and adds +1 every repetition.
Angius
Angius8mo ago
Easiest way would be splitting the string on whitespace That way you get an array of individual words
TheOne1984
TheOne19848mo ago
Thats another issue, it has to be done with tools used in class and that is something we have not seen yet
Sweerpotato
Sweerpotato8mo ago
Yes, it depends on what output you're expecting
TheOne1984
TheOne19848mo ago
I was thinking switch
Angius
Angius8mo ago
So you're looking at making your own parser, basically
TheOne1984
TheOne19848mo ago
For instance: string = "Hello hello hello"; and the console shows: There are 3 Hello in your text.
nohopestage
nohopestage8mo ago
What tools have you used in class?
Sweerpotato
Sweerpotato8mo ago
is "ZZZZZ" considered two words if you're looking for ZZZ?
TheOne1984
TheOne19848mo ago
switch case, else if, and so on
Sweerpotato
Sweerpotato8mo ago
Or even three
TheOne1984
TheOne19848mo ago
Not so advanced tools yet
Sweerpotato
Sweerpotato8mo ago
Ah ok
nohopestage
nohopestage8mo ago
That's pretty limiting. No for/foreach?
TheOne1984
TheOne19848mo ago
For each too, while as well For Some arrays
nohopestage
nohopestage8mo ago
Lol
TheOne1984
TheOne19848mo ago
Let me share a screenshot of my work so far
MODiX
MODiX8mo ago
Angius
REPL Result: Success
var str = "Hello world four words";
var words = new List<string>();

var word = new List<char>();
foreach(char ch in str + " ")
{
if (char.IsWhiteSpace(ch))
{
words.Add(new string(word.ToArray()));
word.Clear();
}
else
{
word.Add(ch);
}
}

words
var str = "Hello world four words";
var words = new List<string>();

var word = new List<char>();
foreach(char ch in str + " ")
{
if (char.IsWhiteSpace(ch))
{
words.Add(new string(word.ToArray()));
word.Clear();
}
else
{
word.Add(ch);
}
}

words
Result: List<string>
[
"Hello",
"world",
"four",
"words"
]
[
"Hello",
"world",
"four",
"words"
]
Compile: 635.947ms | Execution: 51.530ms | React with ❌ to remove this embed.
Angius
Angius8mo ago
There A very manual way to split a string into words
TheOne1984
TheOne19848mo ago
But we have not seen things like IsWhiteSpace
Angius
Angius8mo ago
Ah, well, RIP You can try just checking == ' '
Sweerpotato
Sweerpotato8mo ago
Okay but maybe we can explain what in the world is going on
Angius
Angius8mo ago
It will work only with spaces, tho
TheOne1984
TheOne19848mo ago
Exactly my issue
Sweerpotato
Sweerpotato8mo ago
You have an input string, right? Instead of spoon-feeding you the solution let's arrive at it
TheOne1984
TheOne19848mo ago
okay yes
Sweerpotato
Sweerpotato8mo ago
Yes, so you have an input string and you want to count the words?
TheOne1984
TheOne19848mo ago
Yes
Sweerpotato
Sweerpotato8mo ago
So "for each" word you have to do something
TheOne1984
TheOne19848mo ago
Like the repetition of certain words Yes
Sweerpotato
Sweerpotato8mo ago
And if you're looking for certain words you have to save them somehow
TheOne1984
TheOne19848mo ago
Yes?
Sweerpotato
Sweerpotato8mo ago
Do you know how to declare variables?
TheOne1984
TheOne19848mo ago
This is an example of what I did to count the consonants else if (char.Parse(letter.ToUpper()) == 65 char.Parse(letter.ToUpper()) == 69 char.Parse(letter.ToUpper()) == 73 char.Parse(letter.ToUpper()) == 79 char.Parse(letter.ToUpper()) == 85)
Angius
Angius8mo ago
$code
MODiX
MODiX8mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
TheOne1984
TheOne19848mo ago
Using ASCII table values
Angius
Angius8mo ago
Why use ASCII values? And not just theChar == 'g'
TheOne1984
TheOne19848mo ago
They didnt teach us that
Angius
Angius8mo ago
They didn't teach you what?
Sweerpotato
Sweerpotato8mo ago
It's a "trick"
TheOne1984
TheOne19848mo ago
theChar
Angius
Angius8mo ago
You have comparison in your code, == You are using chars Everything seems to be there
TheOne1984
TheOne19848mo ago
Fair, but then my issue remains for words
Sweerpotato
Sweerpotato8mo ago
'g' and 103 have the same value
Angius
Angius8mo ago
Well, 'g' and (char)103 do Or (int)'g' and 103
Sweerpotato
Sweerpotato8mo ago
Words are similar You can iterate over your string and check
TheOne1984
TheOne19848mo ago
How do you do that?
Sweerpotato
Sweerpotato8mo ago
So if you have a string separated by regular spaces you can just write a for each-loop foreach (string word in yourLargeString.Split(' '))
TheOne1984
TheOne19848mo ago
But for instance I have never used Split
Sweerpotato
Sweerpotato8mo ago
hm okay, do you need to do it without that?
TheOne1984
TheOne19848mo ago
Most probably yes
Sweerpotato
Sweerpotato8mo ago
In that case you need to iterate over each character and check if a character is space char == ' ' and separate words that way
Angius
Angius8mo ago
Like in my example, yeah
TheOne1984
TheOne19848mo ago
But why a space?
Sweerpotato
Sweerpotato8mo ago
space as a word separator
Angius
Angius8mo ago
What delimites words in a sentence?
TheOne1984
TheOne19848mo ago
But is that going to count every word in the text?
Sweerpotato
Sweerpotato8mo ago
Depends how you implement it you could count how many spaces you encounter
TheOne1984
TheOne19848mo ago
I have counted the spaces with char == 32
Angius
Angius8mo ago
No description
Angius
Angius8mo ago
Why not char = ' '?
TheOne1984
TheOne19848mo ago
No description
TheOne1984
TheOne19848mo ago
Finally got it The word I need to count is "Dante", which is inside the string
Angius
Angius8mo ago
Wait, you want to only count the occurences of Dante?
TheOne1984
TheOne19848mo ago
Dante, Virgilio, chant and infernus
Angius
Angius8mo ago
Ah
TheOne1984
TheOne19848mo ago
Those four basically
Angius
Angius8mo ago
Well, you would still run a parser in a loop, then I... think that's what you're doing
Sweerpotato
Sweerpotato8mo ago
Yes
Angius
Angius8mo ago
All that useless code kinda obstructs what's happening, and I can't remember what ASCII value each char has lol
TheOne1984
TheOne19848mo ago
Sorry
Angius
Angius8mo ago
Nothing to be sorry for, we all started by writing bad code
TheOne1984
TheOne19848mo ago
It works to count letter, but not a whole world
Angius
Angius8mo ago
But you really could use to replace all those char.Parse(letter.ToUpper()) == 65 with just letter == 'v' etc
TheOne1984
TheOne19848mo ago
Bit would I have to repeat that for each letter?
Angius
Angius8mo ago
The way you're doing it right now, yes But with much less code And the ability to actually, you know, see the letter Who tf can remember what letter 65 is
Sweerpotato
Sweerpotato8mo ago
I was about to say, this counts the letters in Divine_Comedy
TheOne1984
TheOne19848mo ago
Yes But I'm looking for a way to get the word Dante and count it
Sweerpotato
Sweerpotato8mo ago
Okay, so use .split
Angius
Angius8mo ago
Can't Because teachers are stupid
TheOne1984
TheOne19848mo ago
The thing we didn't use Split in class Yea
Angius
Angius8mo ago
So Loop over all the letters
Sweerpotato
Sweerpotato8mo ago
.
Angius
Angius8mo ago
If you encounter ' ' that's a new word
Sweerpotato
Sweerpotato8mo ago
What in the world Yeah
Angius
Angius8mo ago
If you encounter 'd' you migh't be at Dante, so keep going at it See if the next one is a, then n, etc
TheOne1984
TheOne19848mo ago
Yes, but it has to count how many times the word Dante appeats
Angius
Angius8mo ago
If it's not d, then maybe it's v In that case, start looking for letters in vergil If you find all letters of a given word Increment a variable
TheOne1984
TheOne19848mo ago
But what about Dante and Dog? That would ass two Oh I get what you mean, nvm
Angius
Angius8mo ago
Yeah, so if the next letter after d is a, see if the next ones are nte
TheOne1984
TheOne19848mo ago
With a loop?
Angius
Angius8mo ago
If you have o after d, well, that's no longer Dante Yeah A for loop maybe even So you can look ahead If string[i] is d, then check if string[i+1] is a, string[i+2] is n, etc
TheOne1984
TheOne19848mo ago
For Divine_Comedy = D then A?
Sweerpotato
Sweerpotato8mo ago
I'm so sorry, it's very stupid to not use the built-in functions to accomplish what you're doing. Why are they teaching you this way? It's very convoluted
TheOne1984
TheOne19848mo ago
I don't know, this man is truly stupid
Angius
Angius8mo ago
They're teaching the 1997 way, which is about when the teacher probably stopped learning It's all too common
TheOne1984
TheOne19848mo ago
So an if for the string and it keeps checking?
Angius
Angius8mo ago
Yes, you would certainly use an if Could use a substring instead of checking individual letters, if that's something you used
TheOne1984
TheOne19848mo ago
We did
Angius
Angius8mo ago
That'll make things easier, then
TheOne1984
TheOne19848mo ago
if string.Substring == "D"
Angius
Angius8mo ago
When you encounter a space at index i, check if the substring at i + 1 with length 5 is equal to dante That means you got the word Boom If not, check if the substring at i + 1 of length 6 is vergil Etc
TheOne1984
TheOne19848mo ago
So when my n = space then I try the substring?
Angius
Angius8mo ago
ye
nohopestage
nohopestage8mo ago
That would result in an IndexOutOfRangeException when the string ends though
Angius
Angius8mo ago
It could, true So make sure that i + 1 + 6 for, say, vergil doesn't exceed string length
TheOne1984
TheOne19848mo ago
The leght is like 60000
nohopestage
nohopestage8mo ago
Don't use 60000, use string.Length instead
Angius
Angius8mo ago
You can still run into out of range exception if the last word is cat and you're trying to get a substring of length 6
TheOne1984
TheOne19848mo ago
In my case the last word has nothing to do with the ones i am cpunting
Angius
Angius8mo ago
But you will still be checking it If it's dog You would still check substring of length 5 for dante And a substring of length 6 for vergil And You can't, because it's only 3 characters So, index out of range
TheOne1984
TheOne19848mo ago
But its like a 9 letter word
Angius
Angius8mo ago
Sigh Okay, sure Don't check for it, then
nohopestage
nohopestage8mo ago
You could check if, for example, i + 5 does not exceed string.Length
Angius
Angius8mo ago
But know that the code will break if the last word is less than 5 letters
TheOne1984
TheOne19848mo ago
Sorry, I am trying my best to understant I have something like this for (int n = 0; n <= 60000; n++) { letter = Divine_Comedy.Substring(n, 1); if (char.Parse(letter) == 32) { Divine_Comedy.Substring(n, letter.Length + 1); } }
Angius
Angius8mo ago
uh You can get the char with just divineComedy[n] no need for substring there That would mean you get a char, too, and not a string So you can do letter = ' ' Without the parsing and magic numbers
TheOne1984
TheOne19848mo ago
for (int n = 0; n <= 60000; n++) { letter = Divine_Comedy.Substring(n, 1); if (letter = ' ') { Divine_Comedy.Substring(n, letter.Length + 1); } } Like that?
Angius
Angius8mo ago
Well, almost Divine_Comedy.Substring(n, letter.Length + 1); this does nothing letter will always have the length of 1 dante has 5 letters So, if the divineComedy[n] is ' ', check if divineComedy.Substring(n+1, 5) == "dante" Preferably .ToLower() the divineComedy string beforehand, though Or use .Equals("dante", StringComparison.OrdinalIgnoreCase) to ignore the case
Sweerpotato
Sweerpotato8mo ago
Oh, you're allowed to use substring?
TheOne1984
TheOne19848mo ago
for (int n = 0; n <= 60000; n++) { if (Divine_Comedy.Substring(n + 1, 5) == "dante"); { D_V++; } } Like this? Substrings yes
Sweerpotato
Sweerpotato8mo ago
IndexOf?
TheOne1984
TheOne19848mo ago
We used Index positions
Angius
Angius8mo ago
Something like that, yeah
TheOne1984
TheOne19848mo ago
And how do you add the ToLower, or where?
Angius
Angius8mo ago
whereN...?
TheOne1984
TheOne19848mo ago
I meant where
Angius
Angius8mo ago
To your string, ideally var divineComedy = "the text of divine comedy...".ToLower();
TheOne1984
TheOne19848mo ago
You can add to the string?
Angius
Angius8mo ago
Yes
TheOne1984
TheOne19848mo ago
Omg stupid ass teacher I have
MODiX
MODiX8mo ago
Angius
REPL Result: Success
"HeLlo wOrLd".ToLower()
"HeLlo wOrLd".ToLower()
Result: string
hello world
hello world
Compile: 452.559ms | Execution: 36.748ms | React with ❌ to remove this embed.
TheOne1984
TheOne19848mo ago
I got like 6000 Then added the ToLower and now I have 0
Angius
Angius8mo ago
..? How'd you do that?
TheOne1984
TheOne19848mo ago
Maybe it wasnt that I deleted it and still get 0
Angius
Angius8mo ago
Then something else is fucky-wucky
TheOne1984
TheOne19848mo ago
for (int n = 0; n <= 60000; n++) { if (Divine_Comedy.Substring(n + 1, 5) == "Dante") { D_V++; } } I have this
Angius
Angius8mo ago
Well, if your string has been .ToLower()ed, it will... not have uppercase characters anymore So "Dante" will not be found Look for "dante"
TheOne1984
TheOne19848mo ago
I took the ToLower out and ran it like that Put the ToLower and ran dante, still nothing 0 names
Sweerpotato
Sweerpotato8mo ago
This problem is pissing me off Because you're not allowed to use realistic functions
TheOne1984
TheOne19848mo ago
It is to me too 🥲 I know I cant figure out the issue
Angius
Angius8mo ago
Post your code In it's entirety $paste
MODiX
MODiX8mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
nohopestage
nohopestage8mo ago
You're not checking if the current character is a whitespace here
TheOne1984
TheOne19848mo ago
the = ' '
nohopestage
nohopestage8mo ago
Yes Although I'd assume it should still work
TheOne1984
TheOne19848mo ago
for (int n = 0; n <= 60000; n++) { letter = Divine_Comedy.Substring(n, 1); if (letter = ' ') { if (Divine_Comedy.Substring(n + 1, 5) == "dante") { names++; } } } Like that?
nohopestage
nohopestage8mo ago
Yes, if you called ToLower on Divine_Comedy
TheOne1984
TheOne19848mo ago
I did
Angius
Angius8mo ago
letter would be a string, wouldn't it?
TheOne1984
TheOne19848mo ago
Cannot convert char to string on the = ' '
Angius
Angius8mo ago
And you use letter = ' ' instead of letter == ' '
char letter;

for (int n = 0; n <= Divine_Comedy.Length; n++)
{
letter = Divine_Comedy[n];
if (letter = ' ')
{
if (Divine_Comedy.Substring(n + 1, 5) == "dante")
{
names++;
}
}
}
char letter;

for (int n = 0; n <= Divine_Comedy.Length; n++)
{
letter = Divine_Comedy[n];
if (letter = ' ')
{
if (Divine_Comedy.Substring(n + 1, 5) == "dante")
{
names++;
}
}
}
TheOne1984
TheOne19848mo ago
Isnt that declared in the variables?
Angius
Angius8mo ago
Like this .Substring() returns a string ' ' is a char Square peg does not fit round hole
TheOne1984
TheOne19848mo ago
So letter should be declared as char?
Angius
Angius8mo ago
Yes See my example
TheOne1984
TheOne19848mo ago
But then the other part is marked under red
nohopestage
nohopestage8mo ago
Have you used IndexOf?
Angius
Angius8mo ago
Then fix that other part What use for indexof would there be?
Sweerpotato
Sweerpotato8mo ago
string why = "abcd defe eorigeojri DANTE eoir jt gjeoroi DANTE oeiroi gemoiroikgoi er oiero ioie DANTEgmneroigm DANT";
string whyToLower = why.ToLower();
int danteResult = 0;
int start = 0;

while (whyToLower.IndexOf("dante", start) != -1)
{
++danteResult;
start += whyToLower.IndexOf("dante", start);
}

Console.WriteLine("numbers of dante: " + danteResult);
string why = "abcd defe eorigeojri DANTE eoir jt gjeoroi DANTE oeiroi gemoiroikgoi er oiero ioie DANTEgmneroigm DANT";
string whyToLower = why.ToLower();
int danteResult = 0;
int start = 0;

while (whyToLower.IndexOf("dante", start) != -1)
{
++danteResult;
start += whyToLower.IndexOf("dante", start);
}

Console.WriteLine("numbers of dante: " + danteResult);
nohopestage
nohopestage8mo ago
Checking for the next whitespace to get start/end indices of the next word
Sweerpotato
Sweerpotato8mo ago
Trying to spoiler tag it discord is making my life hard It sort of works without edge cases
Angius
Angius8mo ago
Yeah, fair enough. Otherwise we'd find danteian and it'd count for dante
TheOne1984
TheOne19848mo ago
I am still confused
Sweerpotato
Sweerpotato8mo ago
Its so stupid
nohopestage
nohopestage8mo ago
@TheOne1984
TheOne1984
TheOne19848mo ago
I am not sure if we used that Is it the same as the index position ?
Sweerpotato
Sweerpotato8mo ago
Yes The index of a selected character
TheOne1984
TheOne19848mo ago
Cant we do it this way?
nohopestage
nohopestage8mo ago
Should be able to. What error(s) are you currently getting?
TheOne1984
TheOne19848mo ago
Cant convert char to string on the = ' '
Sweerpotato
Sweerpotato8mo ago
(char)' ' or (string)' '
nohopestage
nohopestage8mo ago
That's because letter is a string
TheOne1984
TheOne19848mo ago
Yes, so do I char.Parse it?
Sweerpotato
Sweerpotato8mo ago
no, just typecast it C# is a nice friend that way
nohopestage
nohopestage8mo ago
You could do == " ", but it's better to just change letter to char
Angius
Angius8mo ago
Or use the indexer already
nohopestage
nohopestage8mo ago
^
Angius
Angius8mo ago
Instead of getting a substring of length 1 This will be the last time I mention it Do what you will with this information
Sweerpotato
Sweerpotato8mo ago
ZZ++ is correct
TheOne1984
TheOne19848mo ago
Idk that But the rest of the code uses letter as string, even though ZZZZZZZZ suggest using =
Sweerpotato
Sweerpotato8mo ago
-> (int)2.3f is typecasting to 2 (integer) but listen to ZZ
nohopestage
nohopestage8mo ago
char letter = Divine_Comedy[0];
TheOne1984
TheOne19848mo ago
I tried the == " " and still get 0
Sweerpotato
Sweerpotato8mo ago
letters are strings do you know of ASCII?
TheOne1984
TheOne19848mo ago
Yes, i used it for the other part
nohopestage
nohopestage8mo ago
Well, there's no need to. You could change the code
TheOne1984
TheOne19848mo ago
Oh no... I am so lost
Sweerpotato
Sweerpotato8mo ago
This is not a problem that should be hard it's stupid
TheOne1984
TheOne19848mo ago
Its hard because we cant use other tools
Sweerpotato
Sweerpotato8mo ago
Yes, it's artificially hard for no reason I tried solving it put it in a spoiler up above but I don't want to spoon-feed you the solution
TheOne1984
TheOne19848mo ago
I saw it, dont know many of those tools
Sweerpotato
Sweerpotato8mo ago
it was only loops and indexof?
TheOne1984
TheOne19848mo ago
Oh true
Sweerpotato
Sweerpotato8mo ago
By god I hope you can use that It's so stupid though I've worked with .NET and C# for 8 years literally never had encountered this situation "you can't use split"
TheOne1984
TheOne19848mo ago
He didnt even teach us Split And I still cant do this
Sweerpotato
Sweerpotato8mo ago
It's a hard problem when you can't use library functions You have to reinvent the wheel
TheOne1984
TheOne19848mo ago
🥲
Sweerpotato
Sweerpotato8mo ago
Do you get it to work with my algorithm? I detest copy-paste but what the fuck
TheOne1984
TheOne19848mo ago
Havnt tried it, seems to advanced compared to my level
Sweerpotato
Sweerpotato8mo ago
How.. how can you make it less advanced? I mean Not using split is making it much less advanced
TheOne1984
TheOne19848mo ago
for (int n = 0; n <= Divine_Comedy.Length; n++) { letter = Divine_Comedy.Substring(n, 1); if (letter == " ") { if (Divine_Comedy.Substring(n + 1, 5) == "dante") { names++; } } } Like that was going somewhere
Sweerpotato
Sweerpotato8mo ago
are you forced to use that?
TheOne1984
TheOne19848mo ago
Its the way he taught us
Sweerpotato
Sweerpotato8mo ago
wait you're using substring there
TheOne1984
TheOne19848mo ago
Yes
Sweerpotato
Sweerpotato8mo ago
wtf
TheOne1984
TheOne19848mo ago
That he taught us
Sweerpotato
Sweerpotato8mo ago
no wait wtf are you allowed to use substring???
TheOne1984
TheOne19848mo ago
yes
Sweerpotato
Sweerpotato8mo ago
I stick to this until we can use sensible methods Bug prone but the premise is weird af this will literally never happen to you in real life
TheOne1984
TheOne19848mo ago
Pain... I dont know how to solve this
Sweerpotato
Sweerpotato8mo ago
Show us what you got right now
TheOne1984
TheOne19848mo ago
No description
Sweerpotato
Sweerpotato8mo ago
deus nobiscum sit so eh your assignment is to expand the for-loop? if I interpret this problem correctly?
TheOne1984
TheOne19848mo ago
My assignment is to count the Dantes
Sweerpotato
Sweerpotato8mo ago
okay the vowels, consonants and punctuations are a hint
TheOne1984
TheOne19848mo ago
How so?
Sweerpotato
Sweerpotato8mo ago
I suppose you're supposed to have an if-clause for 'd'
nohopestage
nohopestage8mo ago
I mean, you could use other methods if you consider the string type a tool
Sweerpotato
Sweerpotato8mo ago
or 'D' like if (char.Parse(letter.ToUpper())) == 'D')
TheOne1984
TheOne19848mo ago
Ill do anything that solves this If "D" then names++
Sweerpotato
Sweerpotato8mo ago
Not really, use substring to follow up on "ante" because you checked if "D" was present or you check substring with current index (D) + "ante" you're going to be interrupted by the consonant if-clause since D is a consonant so you need to implement your if-clause in the consonant space
TheOne1984
TheOne19848mo ago
So if D, the ante, then names ++
Sweerpotato
Sweerpotato8mo ago
Yeah, and D only occurs in this case
No description
TheOne1984
TheOne19848mo ago
Yes
Sweerpotato
Sweerpotato8mo ago
and if you're in that case you can check the substring I think that's what your professor's getting at
TheOne1984
TheOne19848mo ago
So after consonants++ if (char.Parse(letter.ToUpper())) == 'D') if ante names++;
Sweerpotato
Sweerpotato8mo ago
That's the pseudo-code, yeah you got it my friend just let the professor's framework do whatever the fuck he thought was good and scalpel in the thing you apparently were supposed to sorry for cursing
TheOne1984
TheOne19848mo ago
Its fine I still cant figure this out, i get your idea
Sweerpotato
Sweerpotato8mo ago
you're almost there you just need to substring words
TheOne1984
TheOne19848mo ago
I get lots of errors after the consonats++
Sweerpotato
Sweerpotato8mo ago
What do the errors say
TheOne1984
TheOne19848mo ago
No description
nohopestage
nohopestage8mo ago
Remove the ) after ToUpper())
TheOne1984
TheOne19848mo ago
That fixed some issues
nohopestage
nohopestage8mo ago
What does it say now?
TheOne1984
TheOne19848mo ago
if (char.Parse(letter.ToUpper()) == 'D') { if() { names++; } } I have this
nohopestage
nohopestage8mo ago
There's an empty if statement, put the Substring part in there
TheOne1984
TheOne19848mo ago
Like Divine_Comedy.Substring(n +1, 5)
nohopestage
nohopestage8mo ago
Yeah, but remove the +1 part
TheOne1984
TheOne19848mo ago
oh ok It says D_C is null { consonants++; if (char.Parse(letter.ToUpper()) == 'D') { if(Divine_Comedy.Substring(n, 5)) { names++; } } }
nohopestage
nohopestage8mo ago
What's D_C?
TheOne1984
TheOne19848mo ago
Divine_Comedy, to simplify
nohopestage
nohopestage8mo ago
Uhh, that's not true Can I see the error?
TheOne1984
TheOne19848mo ago
No description
nohopestage
nohopestage8mo ago
Do if (Divine_Comedy.Substring(n, 5) == "Dante")
TheOne1984
TheOne19848mo ago
No description
nohopestage
nohopestage8mo ago
Change <= to < at the for(...) line
TheOne1984
TheOne19848mo ago
Solved the mistake, but names = 0
nohopestage
nohopestage8mo ago
You're doing it like this, right?
TheOne1984
TheOne19848mo ago
No description
TheOne1984
TheOne19848mo ago
Yes
nohopestage
nohopestage8mo ago
Remove the first if statement after consonants++;
TheOne1984
TheOne19848mo ago
No description
TheOne1984
TheOne19848mo ago
I got this
nohopestage
nohopestage8mo ago
That's better, not sure why the first check fails though
TheOne1984
TheOne19848mo ago
And how do we fix this?
nohopestage
nohopestage8mo ago
Replace it with if (n + 5 < Divine_Comedy.Length)
TheOne1984
TheOne19848mo ago
And the "Dante"?
nohopestage
nohopestage8mo ago
No, like this
TheOne1984
TheOne19848mo ago
Do I put it again like that?
nohopestage
nohopestage8mo ago
Yes, but use the if statement I provided instead of the old one
TheOne1984
TheOne19848mo ago
For the second one, right?
nohopestage
nohopestage8mo ago
The first one
TheOne1984
TheOne19848mo ago
I did that and names = 0 I changed the second one and names = 17,000 +
nohopestage
nohopestage8mo ago
Is it this with the Dante check inside?
TheOne1984
TheOne19848mo ago
No description
TheOne1984
TheOne19848mo ago
Yes, and names = 0
nohopestage
nohopestage8mo ago
Can you post your code? $paste
MODiX
MODiX8mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
TheOne1984
TheOne19848mo ago
int vowels = 0, consonants = 0, space = 0, punctuation = 0, lines = 0, names = 0, infernus = 0, numbers = 0, chant = 0; for (int n = 0; n < Divine_Comedy.Length; n++) { letter = Divine_Comedy.Substring(n, 1); if (char.Parse(letter) == 32) { space++; } else if (char.Parse(letter.ToUpper()) == 65 char.Parse(letter.ToUpper()) == 69 char.Parse(letter.ToUpper()) == 73 char.Parse(letter.ToUpper()) == 79 char.Parse(letter.ToUpper()) == 85) { vowels++; } else if (char.Parse(letter.ToUpper()) > 65 && char.Parse(letter.ToUpper()) < 69 char.Parse(letter.ToUpper()) > 69 && char.Parse(letter.ToUpper()) < 73 char.Parse(letter.ToUpper()) > 73 && char.Parse(letter.ToUpper()) < 79 char.Parse(letter.ToUpper()) > 79 && char.Parse(letter.ToUpper()) < 85 char.Parse(letter.ToUpper()) > 85 && char.Parse(letter.ToUpper()) < 90) { consonants++; if (n + 5 < Divine_Comedy.Length) { if(Divine_Comedy.Substring(n, 5) == "Dante") { names++; } } } else if (char.Parse(letter.ToUpper()) == 33 char.Parse(letter.ToUpper()) == 34 char.Parse(letter.ToUpper()) == 40 char.Parse(letter.ToUpper()) == 44 char.Parse(letter.ToUpper()) == 45 char.Parse(letter.ToUpper()) == 46 char.Parse(letter.ToUpper()) == 58 char.Parse(letter.ToUpper()) == 59 char.Parse(letter.ToUpper()) == 63 char.Parse(letter.ToUpper()) == 94 char.Parse(letter.ToUpper()) == 174) { punctuation++; } }
nohopestage
nohopestage8mo ago
I'll play around and see if I can figure it out
TheOne1984
TheOne19848mo ago
Console.WriteLine("This text has " + (vowels + consonants) + " letters.\n"); Console.WriteLine("This text has " + vowels + " vowels.\n"); Console.WriteLine("This text has " + consonants + " consonants.\n"); Console.WriteLine("This text has " + space + " blank spaces.\n"); Console.WriteLine("This text has " + lines + " lines.\n"); Console.WriteLine("This song has " + punctuation + " puntuation signs.\n"); Console.WriteLine("This text mentions Dante and Vergilio " + names + " times.\n"); Console.WriteLine("This text says the word 'infierno' " + infernus + " times.\n"); Console.WriteLine("This text has " + numbers + " numbers.\n"); Console.WriteLine("This text says the word chant " + chant + " times.\n"); All but the giagant string
nohopestage
nohopestage8mo ago
Post it on this website
TheOne1984
TheOne19848mo ago
BlazeBin - qlmwxeejmxes
A tool for sharing your source code with the world!
nohopestage
nohopestage8mo ago
Can't copy it on my phone. Please post it on https://dotnetfiddle.net/
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
TheOne1984
TheOne19848mo ago
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
nohopestage
nohopestage8mo ago
Change < to <=
TheOne1984
TheOne19848mo ago
With you if chang?
nohopestage
nohopestage8mo ago
Hmm?
TheOne1984
TheOne19848mo ago
Your new if change?
nohopestage
nohopestage8mo ago
Yes In this one
TheOne1984
TheOne19848mo ago
No description
TheOne1984
TheOne19848mo ago
Error
nohopestage
nohopestage8mo ago
No, this
TheOne1984
TheOne19848mo ago
Oh, let me try names = 0
nohopestage
nohopestage8mo ago
What's the code now?
TheOne1984
TheOne19848mo ago
consonants++; if (n + 5 <= Divine_Comedy.Length) { if(Divine_Comedy.Substring(n, 5) == "Dante") { names++; } } }
nohopestage
nohopestage8mo ago
That's weird, it's working for me
TheOne1984
TheOne19848mo ago
It is??? Can you share it?
nohopestage
nohopestage8mo ago
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
TheOne1984
TheOne19848mo ago
It works on the web, bt not mine
nohopestage
nohopestage8mo ago
Just copy the code then
TheOne1984
TheOne19848mo ago
I did It works with the small string Not the big one
nohopestage
nohopestage8mo ago
Can you share the big one?
TheOne1984
TheOne19848mo ago
Sure
TheOne1984
TheOne19848mo ago
Thats the big string only
nohopestage
nohopestage8mo ago
Oh, you have ToLower there. So you need to check for dante Or just remove ToLower
TheOne1984
TheOne19848mo ago
Oooooh It says 4 four Dante and like 33 for Virgilio Two for Dante and 33 for Virgilio I think it works It works Thank you so muc all that helped me, I dont want to tag you so I dont bother you, but Thank You So Much
nohopestage
nohopestage8mo ago
Did you remove ToLower? $close
MODiX
MODiX8mo ago
Use the /close command to mark a forum thread as answered
nohopestage
nohopestage8mo ago
Assuming you did. Glad it works for you
Angius
Angius8mo ago
🎉
nohopestage
nohopestage8mo ago
Just in case, 4 is not accurate because there are words that have dante in them
TheOne1984
TheOne19848mo ago
Oh yeah, fixed that after it got marked ty
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.