Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a textbox2.text and I declare this as a string namely myletters
and I also have a label36.text and i also declare this as a string namely patterns

I will only input on the textbox is letters from "a" to "z" only and the reason why there is a label36 is that when i put the same letter again it will show an error message.

This is my code so far.
-----------------------------------------------------------------------------------------
Imports System.Text.RegularExpressions


VB
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim patterns As String
        patterns = Label36.Text
        Dim myletters As String
        myletters = TextBox2.Text
        Dim matches As MatchCollection = Regex.Matches(myletters, patterns)
        If Regex.IsMatch(patterns, myletters) Then
            MsgBox("You already typed this letter.")
        Else
            Label36.Text = Label36.Text + myletters + ","
            End If
    End Sub



----------------------------------------------------------------------------------------

What use on the top is my code so far that will show error if i already put a same letter again and give this if i dont put the same letters.


Example Output:

Set A: a,b,c,d,e


Now here is my questions.
1.How can i input my first letter without following a comma?
Example:
a

But my output is
Example:
a,
2.How can i set my textbox to the maximum of input of just 1 letter?
3.How can i put commas in right time and format?
Example 1:
a
Example 2:
a,b
But my example is
Example 1:
a,
Example 2:
a,b,
4.How can i arrange the alphabet letters in the right positions?
Example 1:
a,z
If i will input "x" the output must be
Example 2:
a,x,z



Thank you, any answer will be accepted TY.

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 21-Jul-13 0:32am
v4
Comments
OriginalGriff 21-Jul-13 6:27am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Crixalis Paul 21-Jul-13 6:33am    
Sorry for what I've Done
OriginalGriff 21-Jul-13 6:37am    
It's ok - just think about it before you post in caps again! :laugh:

1 solution

There are a number of ways to do this, and the simplest is probably not to use a regex at all - bear in mind that
a,b
in your label as a regex looks for exactly that: an 'a', followed by a comma, followed by a 'b' - so if your text contains "a,c" it will not match...

Instead, think about setting up a List of strings, and add each new character to it as you go.
You can then check if the list has a letter already using the List.Contains method and add it if it doesn't. You can sort the list using List.Sort, and create a comma delimited string for presentation using string.Join.
 
Share this answer
 
Comments
Crixalis Paul 21-Jul-13 6:40am    
Sorry sir :(
how can i code this?
Crixalis Paul 21-Jul-13 6:52am    
Sir please give me a sample code and i will continue the rest of it just a hint sir
OriginalGriff 21-Jul-13 7:05am    
Which bit do you need help with? I'm reluctant to give you the lot, because you won't learn as well if I do - but I don't know what you do know, if you see what I mean! :laugh:
Crixalis Paul 21-Jul-13 7:13am    
I already answer my question number 2 please help me on the first question please. just on the first question
OriginalGriff 21-Jul-13 7:23am    
Ok - you know how to create a list of strings and add items to it?

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