Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How in vb.net to check for repetition of characters in a string.
what i am trying to do is.. i have a string of "Whatis4compareToABig44Number" i want it to extract repeated
characters like in the string it has repeated character "40maeri".
it also will be Case sensitive thats why "T: is ommitted.
dont know how to go about this.
All this are the requirements in my software that got me hooked.

What I have tried:

don't know how to go about this
Posted
Updated 4-Apr-23 23:37pm
Comments
phil.o 10-May-20 14:32pm    
Answering your now deleted comment, I showed you one of many ways to accomplish your requirement. As a developper, producing this kind of pseudo-code is the very first thing that you should be able to do. You showed no attempt at all on your side, stating that you don't know how to go about it. I just put you on the road, providing a direction. Now, it is up to you to follow it and provide some work of your own. The important thing here is not the final result, but rather the steps you have to follow to get to it. Put in other terms, in a learning process, the journey is way more important than the destination itself.
BillWoodruff 6-Dec-22 12:37pm    
i have a string of "Whatis4compareToABig44Number" i want it to extract repeated
characters like in the string it has repeated character "40maeri".

what is the expected output for this string ?

This is one of possible algorithms:
  • Initialize a dictionary having characters as keys and integers as values.
  • Enumerate the characters in input string.
    • If current character is in the dictionary, increment the value.
    • Otherwise add the character to the dictionary and set the value to 1.
  • Initialize a string builder.
  • Enumerate the characters in the dictionary.
    • If current character has a value greater than one, and is not a capital letter, append it to the string builder.
  • Return the content of the string builder.
 
Share this answer
 
Comments
[no name] 10-May-20 14:23pm    
Please can you explain with code since i am just beginning learning programming.
phil.o 10-May-20 14:33pm    
Please see my comment to your question. I would not be helping you, in the long term, by doing your assignments for you.
George Swan 11-May-20 6:52am    
I think the op wants uppercase and lowercase letters to be treated as separate characters i.e. T and t are not duplicates. It seems to me that a couple of nested 'for' loops is the way to go. Add any duplicates found to a List of duplicates if they are not already contained in that List. When the outer iteration is completed, simply convert the List of duplicates into a char[] and use it as a parameter for the instantiation of the result string.
You have already asked this in your other question at Is there any converter that does this?[^]. You need to first decide whether you are going to use C# or VB.NET. Once you have made that decision then get hold of a good book on the language and study it to get a good understanding of the language and its framework.
 
Share this answer
 
VB
Dim TestString As String = "Whatis4compareToABig44Number"
Dim LstFoundChar As List(Of String) = New List (Of String) 
Dim RepeatedChars As String =""
For i As Integer = 0 to TestString.Length 
 Dim TestChar As String = Strings.Mid(TestString,i,1) 
 If LstFoundChar.Contains(TestChar) Then 
    If RepeatedChars.Contains(TestChar) = False Then
       RepeatedChars= RepeatedChars & TestChar
    End If 
Else 
LstFoundChar.Add (TestChar) 

 End If 
Next 
 
Share this answer
 
Comments
Dave Kreskowiak 27-Apr-23 17:19pm    
Doing someone's homework for them is always a bad idea.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900