C
C#15mo 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
Sweerpotato15mo ago
Can you provide more context? Like what you're trying, what you're expected to output
TheOne1984
TheOne1984OP15mo 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
Angius15mo ago
Easiest way would be splitting the string on whitespace That way you get an array of individual words
TheOne1984
TheOne1984OP15mo ago
Thats another issue, it has to be done with tools used in class and that is something we have not seen yet
Sweerpotato
Sweerpotato15mo ago
Yes, it depends on what output you're expecting
TheOne1984
TheOne1984OP15mo ago
I was thinking switch
Angius
Angius15mo ago
So you're looking at making your own parser, basically
TheOne1984
TheOne1984OP15mo ago
For instance: string = "Hello hello hello"; and the console shows: There are 3 Hello in your text.
nohopestage
nohopestage15mo ago
What tools have you used in class?
Sweerpotato
Sweerpotato15mo ago
is "ZZZZZ" considered two words if you're looking for ZZZ?
TheOne1984
TheOne1984OP15mo ago
switch case, else if, and so on
Sweerpotato
Sweerpotato15mo ago
Or even three
TheOne1984
TheOne1984OP15mo ago
Not so advanced tools yet
Sweerpotato
Sweerpotato15mo ago
Ah ok
nohopestage
nohopestage15mo ago
That's pretty limiting. No for/foreach?
TheOne1984
TheOne1984OP15mo ago
For each too, while as well For Some arrays
nohopestage
nohopestage15mo ago
Lol
TheOne1984
TheOne1984OP15mo ago
Let me share a screenshot of my work so far
MODiX
MODiX15mo 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
Angius15mo ago
There A very manual way to split a string into words
TheOne1984
TheOne1984OP15mo ago
But we have not seen things like IsWhiteSpace
Angius
Angius15mo ago
Ah, well, RIP You can try just checking == ' '
Sweerpotato
Sweerpotato15mo ago
Okay but maybe we can explain what in the world is going on
Angius
Angius15mo ago
It will work only with spaces, tho
TheOne1984
TheOne1984OP15mo ago
Exactly my issue
Sweerpotato
Sweerpotato15mo ago
You have an input string, right? Instead of spoon-feeding you the solution let's arrive at it
TheOne1984
TheOne1984OP15mo ago
okay yes
Sweerpotato
Sweerpotato15mo ago
Yes, so you have an input string and you want to count the words?
TheOne1984
TheOne1984OP15mo ago
Yes
Sweerpotato
Sweerpotato15mo ago
So "for each" word you have to do something
TheOne1984
TheOne1984OP15mo ago
Like the repetition of certain words Yes
Sweerpotato
Sweerpotato15mo ago
And if you're looking for certain words you have to save them somehow
TheOne1984
TheOne1984OP15mo ago
Yes?
Sweerpotato
Sweerpotato15mo ago
Do you know how to declare variables?
TheOne1984
TheOne1984OP15mo 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
Angius15mo ago
$code
MODiX
MODiX15mo 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
TheOne1984OP15mo ago
Using ASCII table values
Angius
Angius15mo ago
Why use ASCII values? And not just theChar == 'g'
TheOne1984
TheOne1984OP15mo ago
They didnt teach us that
Angius
Angius15mo ago
They didn't teach you what?
Sweerpotato
Sweerpotato15mo ago
It's a "trick"
TheOne1984
TheOne1984OP15mo ago
theChar
Angius
Angius15mo ago
You have comparison in your code, == You are using chars Everything seems to be there
TheOne1984
TheOne1984OP15mo ago
Fair, but then my issue remains for words
Sweerpotato
Sweerpotato15mo ago
'g' and 103 have the same value
Angius
Angius15mo ago
Well, 'g' and (char)103 do Or (int)'g' and 103
Sweerpotato
Sweerpotato15mo ago
Words are similar You can iterate over your string and check
TheOne1984
TheOne1984OP15mo ago
How do you do that?
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
But for instance I have never used Split
Sweerpotato
Sweerpotato15mo ago
hm okay, do you need to do it without that?
TheOne1984
TheOne1984OP15mo ago
Most probably yes
Sweerpotato
Sweerpotato15mo 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
Angius15mo ago
Like in my example, yeah
TheOne1984
TheOne1984OP15mo ago
But why a space?
Sweerpotato
Sweerpotato15mo ago
space as a word separator
Angius
Angius15mo ago
What delimites words in a sentence?
TheOne1984
TheOne1984OP15mo ago
But is that going to count every word in the text?
Sweerpotato
Sweerpotato15mo ago
Depends how you implement it you could count how many spaces you encounter
TheOne1984
TheOne1984OP15mo ago
I have counted the spaces with char == 32
Angius
Angius15mo ago
No description
Angius
Angius15mo ago
Why not char = ' '?
TheOne1984
TheOne1984OP15mo ago
No description
TheOne1984
TheOne1984OP15mo ago
Finally got it The word I need to count is "Dante", which is inside the string
Angius
Angius15mo ago
Wait, you want to only count the occurences of Dante?
TheOne1984
TheOne1984OP15mo ago
Dante, Virgilio, chant and infernus
Angius
Angius15mo ago
Ah
TheOne1984
TheOne1984OP15mo ago
Those four basically
Angius
Angius15mo ago
Well, you would still run a parser in a loop, then I... think that's what you're doing
Sweerpotato
Sweerpotato15mo ago
Yes
Angius
Angius15mo ago
All that useless code kinda obstructs what's happening, and I can't remember what ASCII value each char has lol
TheOne1984
TheOne1984OP15mo ago
Sorry
Angius
Angius15mo ago
Nothing to be sorry for, we all started by writing bad code
TheOne1984
TheOne1984OP15mo ago
It works to count letter, but not a whole world
Angius
Angius15mo ago
But you really could use to replace all those char.Parse(letter.ToUpper()) == 65 with just letter == 'v' etc
TheOne1984
TheOne1984OP15mo ago
Bit would I have to repeat that for each letter?
Angius
Angius15mo 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
Sweerpotato15mo ago
I was about to say, this counts the letters in Divine_Comedy
TheOne1984
TheOne1984OP15mo ago
Yes But I'm looking for a way to get the word Dante and count it
Sweerpotato
Sweerpotato15mo ago
Okay, so use .split
Angius
Angius15mo ago
Can't Because teachers are stupid
TheOne1984
TheOne1984OP15mo ago
The thing we didn't use Split in class Yea
Angius
Angius15mo ago
So Loop over all the letters
Sweerpotato
Sweerpotato15mo ago
.
Angius
Angius15mo ago
If you encounter ' ' that's a new word
Sweerpotato
Sweerpotato15mo ago
What in the world Yeah
Angius
Angius15mo 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
TheOne1984OP15mo ago
Yes, but it has to count how many times the word Dante appeats
Angius
Angius15mo 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
TheOne1984OP15mo ago
But what about Dante and Dog? That would ass two Oh I get what you mean, nvm
Angius
Angius15mo ago
Yeah, so if the next letter after d is a, see if the next ones are nte
TheOne1984
TheOne1984OP15mo ago
With a loop?
Angius
Angius15mo 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
TheOne1984OP15mo ago
For Divine_Comedy = D then A?
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
I don't know, this man is truly stupid
Angius
Angius15mo ago
They're teaching the 1997 way, which is about when the teacher probably stopped learning It's all too common
TheOne1984
TheOne1984OP15mo ago
So an if for the string and it keeps checking?
Angius
Angius15mo ago
Yes, you would certainly use an if Could use a substring instead of checking individual letters, if that's something you used
TheOne1984
TheOne1984OP15mo ago
We did
Angius
Angius15mo ago
That'll make things easier, then
TheOne1984
TheOne1984OP15mo ago
if string.Substring == "D"
Angius
Angius15mo 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
TheOne1984OP15mo ago
So when my n = space then I try the substring?
Angius
Angius15mo ago
ye
nohopestage
nohopestage15mo ago
That would result in an IndexOutOfRangeException when the string ends though
Angius
Angius15mo ago
It could, true So make sure that i + 1 + 6 for, say, vergil doesn't exceed string length
TheOne1984
TheOne1984OP15mo ago
The leght is like 60000
nohopestage
nohopestage15mo ago
Don't use 60000, use string.Length instead
Angius
Angius15mo 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
TheOne1984OP15mo ago
In my case the last word has nothing to do with the ones i am cpunting
Angius
Angius15mo 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
TheOne1984OP15mo ago
But its like a 9 letter word
Angius
Angius15mo ago
Sigh Okay, sure Don't check for it, then
nohopestage
nohopestage15mo ago
You could check if, for example, i + 5 does not exceed string.Length
Angius
Angius15mo ago
But know that the code will break if the last word is less than 5 letters
TheOne1984
TheOne1984OP15mo 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
Angius15mo 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
TheOne1984OP15mo 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
Angius15mo 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
Sweerpotato15mo ago
Oh, you're allowed to use substring?
TheOne1984
TheOne1984OP15mo ago
for (int n = 0; n <= 60000; n++) { if (Divine_Comedy.Substring(n + 1, 5) == "dante"); { D_V++; } } Like this? Substrings yes
Sweerpotato
Sweerpotato15mo ago
IndexOf?
TheOne1984
TheOne1984OP15mo ago
We used Index positions
Angius
Angius15mo ago
Something like that, yeah
TheOne1984
TheOne1984OP15mo ago
And how do you add the ToLower, or where?
Angius
Angius15mo ago
whereN...?
TheOne1984
TheOne1984OP15mo ago
I meant where
Angius
Angius15mo ago
To your string, ideally var divineComedy = "the text of divine comedy...".ToLower();
TheOne1984
TheOne1984OP15mo ago
You can add to the string?
Angius
Angius15mo ago
Yes
TheOne1984
TheOne1984OP15mo ago
Omg stupid ass teacher I have
MODiX
MODiX15mo 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
TheOne1984OP15mo ago
I got like 6000 Then added the ToLower and now I have 0
Angius
Angius15mo ago
..? How'd you do that?
TheOne1984
TheOne1984OP15mo ago
Maybe it wasnt that I deleted it and still get 0
Angius
Angius15mo ago
Then something else is fucky-wucky
TheOne1984
TheOne1984OP15mo ago
for (int n = 0; n <= 60000; n++) { if (Divine_Comedy.Substring(n + 1, 5) == "Dante") { D_V++; } } I have this
Angius
Angius15mo 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
TheOne1984OP15mo ago
I took the ToLower out and ran it like that Put the ToLower and ran dante, still nothing 0 names
Sweerpotato
Sweerpotato15mo ago
This problem is pissing me off Because you're not allowed to use realistic functions
TheOne1984
TheOne1984OP15mo ago
It is to me too 🥲 I know I cant figure out the issue
Angius
Angius15mo ago
Post your code In it's entirety $paste
MODiX
MODiX15mo 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
nohopestage15mo ago
You're not checking if the current character is a whitespace here
TheOne1984
TheOne1984OP15mo ago
the = ' '
nohopestage
nohopestage15mo ago
Yes Although I'd assume it should still work
TheOne1984
TheOne1984OP15mo 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
nohopestage15mo ago
Yes, if you called ToLower on Divine_Comedy
TheOne1984
TheOne1984OP15mo ago
I did
Angius
Angius15mo ago
letter would be a string, wouldn't it?
TheOne1984
TheOne1984OP15mo ago
Cannot convert char to string on the = ' '
Angius
Angius15mo 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
TheOne1984OP15mo ago
Isnt that declared in the variables?
Angius
Angius15mo ago
Like this .Substring() returns a string ' ' is a char Square peg does not fit round hole
TheOne1984
TheOne1984OP15mo ago
So letter should be declared as char?
Angius
Angius15mo ago
Yes See my example
TheOne1984
TheOne1984OP15mo ago
But then the other part is marked under red
nohopestage
nohopestage15mo ago
Have you used IndexOf?
Angius
Angius15mo ago
Then fix that other part What use for indexof would there be?
Sweerpotato
Sweerpotato15mo 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
nohopestage15mo ago
Checking for the next whitespace to get start/end indices of the next word
Sweerpotato
Sweerpotato15mo ago
Trying to spoiler tag it discord is making my life hard It sort of works without edge cases
Angius
Angius15mo ago
Yeah, fair enough. Otherwise we'd find danteian and it'd count for dante
TheOne1984
TheOne1984OP15mo ago
I am still confused
Sweerpotato
Sweerpotato15mo ago
Its so stupid
nohopestage
nohopestage15mo ago
@TheOne1984
TheOne1984
TheOne1984OP15mo ago
I am not sure if we used that Is it the same as the index position ?
Sweerpotato
Sweerpotato15mo ago
Yes The index of a selected character
TheOne1984
TheOne1984OP15mo ago
Cant we do it this way?
nohopestage
nohopestage15mo ago
Should be able to. What error(s) are you currently getting?
TheOne1984
TheOne1984OP15mo ago
Cant convert char to string on the = ' '
Sweerpotato
Sweerpotato15mo ago
(char)' ' or (string)' '
nohopestage
nohopestage15mo ago
That's because letter is a string
TheOne1984
TheOne1984OP15mo ago
Yes, so do I char.Parse it?
Sweerpotato
Sweerpotato15mo ago
no, just typecast it C# is a nice friend that way
nohopestage
nohopestage15mo ago
You could do == " ", but it's better to just change letter to char
Angius
Angius15mo ago
Or use the indexer already
nohopestage
nohopestage15mo ago
^
Angius
Angius15mo 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
Sweerpotato15mo ago
ZZ++ is correct
TheOne1984
TheOne1984OP15mo ago
Idk that But the rest of the code uses letter as string, even though ZZZZZZZZ suggest using =
Sweerpotato
Sweerpotato15mo ago
-> (int)2.3f is typecasting to 2 (integer) but listen to ZZ
nohopestage
nohopestage15mo ago
char letter = Divine_Comedy[0];
TheOne1984
TheOne1984OP15mo ago
I tried the == " " and still get 0
Sweerpotato
Sweerpotato15mo ago
letters are strings do you know of ASCII?
TheOne1984
TheOne1984OP15mo ago
Yes, i used it for the other part
nohopestage
nohopestage15mo ago
Well, there's no need to. You could change the code
TheOne1984
TheOne1984OP15mo ago
Oh no... I am so lost
Sweerpotato
Sweerpotato15mo ago
This is not a problem that should be hard it's stupid
TheOne1984
TheOne1984OP15mo ago
Its hard because we cant use other tools
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
I saw it, dont know many of those tools
Sweerpotato
Sweerpotato15mo ago
it was only loops and indexof?
TheOne1984
TheOne1984OP15mo ago
Oh true
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
He didnt even teach us Split And I still cant do this
Sweerpotato
Sweerpotato15mo ago
It's a hard problem when you can't use library functions You have to reinvent the wheel
TheOne1984
TheOne1984OP15mo ago
🥲
Sweerpotato
Sweerpotato15mo ago
Do you get it to work with my algorithm? I detest copy-paste but what the fuck
TheOne1984
TheOne1984OP15mo ago
Havnt tried it, seems to advanced compared to my level
Sweerpotato
Sweerpotato15mo ago
How.. how can you make it less advanced? I mean Not using split is making it much less advanced
TheOne1984
TheOne1984OP15mo 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
Sweerpotato15mo ago
are you forced to use that?
TheOne1984
TheOne1984OP15mo ago
Its the way he taught us
Sweerpotato
Sweerpotato15mo ago
wait you're using substring there
TheOne1984
TheOne1984OP15mo ago
Yes
Sweerpotato
Sweerpotato15mo ago
wtf
TheOne1984
TheOne1984OP15mo ago
That he taught us
Sweerpotato
Sweerpotato15mo ago
no wait wtf are you allowed to use substring???
TheOne1984
TheOne1984OP15mo ago
yes
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
Pain... I dont know how to solve this
Sweerpotato
Sweerpotato15mo ago
Show us what you got right now
TheOne1984
TheOne1984OP15mo ago
No description
Sweerpotato
Sweerpotato15mo ago
deus nobiscum sit so eh your assignment is to expand the for-loop? if I interpret this problem correctly?
TheOne1984
TheOne1984OP15mo ago
My assignment is to count the Dantes
Sweerpotato
Sweerpotato15mo ago
okay the vowels, consonants and punctuations are a hint
TheOne1984
TheOne1984OP15mo ago
How so?
Sweerpotato
Sweerpotato15mo ago
I suppose you're supposed to have an if-clause for 'd'
nohopestage
nohopestage15mo ago
I mean, you could use other methods if you consider the string type a tool
Sweerpotato
Sweerpotato15mo ago
or 'D' like if (char.Parse(letter.ToUpper())) == 'D')
TheOne1984
TheOne1984OP15mo ago
Ill do anything that solves this If "D" then names++
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
So if D, the ante, then names ++
Sweerpotato
Sweerpotato15mo ago
Yeah, and D only occurs in this case
No description
TheOne1984
TheOne1984OP15mo ago
Yes
Sweerpotato
Sweerpotato15mo ago
and if you're in that case you can check the substring I think that's what your professor's getting at
TheOne1984
TheOne1984OP15mo ago
So after consonants++ if (char.Parse(letter.ToUpper())) == 'D') if ante names++;
Sweerpotato
Sweerpotato15mo 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
TheOne1984OP15mo ago
Its fine I still cant figure this out, i get your idea
Sweerpotato
Sweerpotato15mo ago
you're almost there you just need to substring words
TheOne1984
TheOne1984OP15mo ago
I get lots of errors after the consonats++
Sweerpotato
Sweerpotato15mo ago
What do the errors say
TheOne1984
TheOne1984OP15mo ago
No description
nohopestage
nohopestage15mo ago
Remove the ) after ToUpper())
TheOne1984
TheOne1984OP15mo ago
That fixed some issues
nohopestage
nohopestage15mo ago
What does it say now?
TheOne1984
TheOne1984OP15mo ago
if (char.Parse(letter.ToUpper()) == 'D') { if() { names++; } } I have this
nohopestage
nohopestage15mo ago
There's an empty if statement, put the Substring part in there
TheOne1984
TheOne1984OP15mo ago
Like Divine_Comedy.Substring(n +1, 5)
nohopestage
nohopestage15mo ago
Yeah, but remove the +1 part
TheOne1984
TheOne1984OP15mo ago
oh ok It says D_C is null { consonants++; if (char.Parse(letter.ToUpper()) == 'D') { if(Divine_Comedy.Substring(n, 5)) { names++; } } }
nohopestage
nohopestage15mo ago
What's D_C?
TheOne1984
TheOne1984OP15mo ago
Divine_Comedy, to simplify
nohopestage
nohopestage15mo ago
Uhh, that's not true Can I see the error?
TheOne1984
TheOne1984OP15mo ago
No description
nohopestage
nohopestage15mo ago
Do if (Divine_Comedy.Substring(n, 5) == "Dante")
TheOne1984
TheOne1984OP15mo ago
No description
nohopestage
nohopestage15mo ago
Change <= to < at the for(...) line
TheOne1984
TheOne1984OP15mo ago
Solved the mistake, but names = 0
nohopestage
nohopestage15mo ago
You're doing it like this, right?
TheOne1984
TheOne1984OP15mo ago
No description
TheOne1984
TheOne1984OP15mo ago
Yes
nohopestage
nohopestage15mo ago
Remove the first if statement after consonants++;
TheOne1984
TheOne1984OP15mo ago
No description
TheOne1984
TheOne1984OP15mo ago
I got this
nohopestage
nohopestage15mo ago
That's better, not sure why the first check fails though
TheOne1984
TheOne1984OP15mo ago
And how do we fix this?
nohopestage
nohopestage15mo ago
Replace it with if (n + 5 < Divine_Comedy.Length)
TheOne1984
TheOne1984OP15mo ago
And the "Dante"?
nohopestage
nohopestage15mo ago
No, like this
TheOne1984
TheOne1984OP15mo ago
Do I put it again like that?
nohopestage
nohopestage15mo ago
Yes, but use the if statement I provided instead of the old one
TheOne1984
TheOne1984OP15mo ago
For the second one, right?
nohopestage
nohopestage15mo ago
The first one
TheOne1984
TheOne1984OP15mo ago
I did that and names = 0 I changed the second one and names = 17,000 +
nohopestage
nohopestage15mo ago
Is it this with the Dante check inside?
TheOne1984
TheOne1984OP15mo ago
No description
TheOne1984
TheOne1984OP15mo ago
Yes, and names = 0
nohopestage
nohopestage15mo ago
Can you post your code? $paste
MODiX
MODiX15mo 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
TheOne1984OP15mo 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
nohopestage15mo ago
I'll play around and see if I can figure it out
TheOne1984
TheOne1984OP15mo 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
nohopestage15mo ago
Post it on this website
TheOne1984
TheOne1984OP15mo ago
BlazeBin - qlmwxeejmxes
A tool for sharing your source code with the world!
nohopestage
nohopestage15mo 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
TheOne1984OP15mo ago
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
nohopestage
nohopestage15mo ago
Change < to <=
TheOne1984
TheOne1984OP15mo ago
With you if chang?
nohopestage
nohopestage15mo ago
Hmm?
TheOne1984
TheOne1984OP15mo ago
Your new if change?
nohopestage
nohopestage15mo ago
Yes In this one
TheOne1984
TheOne1984OP15mo ago
No description
TheOne1984
TheOne1984OP15mo ago
Error
nohopestage
nohopestage15mo ago
No, this
TheOne1984
TheOne1984OP15mo ago
Oh, let me try names = 0
nohopestage
nohopestage15mo ago
What's the code now?
TheOne1984
TheOne1984OP15mo ago
consonants++; if (n + 5 <= Divine_Comedy.Length) { if(Divine_Comedy.Substring(n, 5) == "Dante") { names++; } } }
nohopestage
nohopestage15mo ago
That's weird, it's working for me
TheOne1984
TheOne1984OP15mo ago
It is??? Can you share it?
nohopestage
nohopestage15mo ago
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
TheOne1984
TheOne1984OP15mo ago
It works on the web, bt not mine
nohopestage
nohopestage15mo ago
Just copy the code then
TheOne1984
TheOne1984OP15mo ago
I did It works with the small string Not the big one
nohopestage
nohopestage15mo ago
Can you share the big one?
TheOne1984
TheOne1984OP15mo ago
Sure
TheOne1984
TheOne1984OP15mo ago
Thats the big string only
nohopestage
nohopestage15mo ago
Oh, you have ToLower there. So you need to check for dante Or just remove ToLower
TheOne1984
TheOne1984OP15mo 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
nohopestage15mo ago
Did you remove ToLower? $close
MODiX
MODiX15mo ago
Use the /close command to mark a forum thread as answered
nohopestage
nohopestage15mo ago
Assuming you did. Glad it works for you
Angius
Angius15mo ago
🎉
nohopestage
nohopestage15mo ago
Just in case, 4 is not accurate because there are words that have dante in them
TheOne1984
TheOne1984OP15mo ago
Oh yeah, fixed that after it got marked ty
Accord
Accord15mo 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.

Did you find this page helpful?