Results 1 to 26 of 26

Thread: Problem Detecting words in Lowercase

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Question Problem Detecting words in Lowercase

    Hi,
    I am creating an IDE and i am having a problem , detecting when a word is in LowerCase , please Help me

    Dim cheackstrings() As String = {"As", "If", "In", "Is", "Me", "On", "To","And","Dim", "End", "For", "Get", "New", "Not", "Sub","Each", "Case", "Else", "Exit", "Like", "Long", "Next", "Step", "Then", "True", "Alias", "ByRef", "ByVal", "Const", "Event", "False", "IsNot", "Short", "Until", "While", "Double", "ElseIf", "Object", "Single", "Static", "String", "Boolean", "Integer", "Variant", "Function"}

    Textbox3 contains the code
    uk in screenshot = you know

    before Clicking on PictureBox2:
    this line (it is a little bit difficult but i will fix it) on screenshot was because i sent it to someone ...
    http://prntscr.com/7iw9ai

    After Clicking:
    http://prntscr.com/7iwafh


    Code:
        Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
            Dim lnNum As Integer = 0
            Dim lines() As String = Textbox3.Lines.ToArray
            For Each Line As String In Textbox3.Text.Split(vbNewLine)
                Line = Line.Replace(vbLf, "")
    
    
                'Dim b As String() = 
                Dim c As String = String.Empty
                Dim h As String = String.Empty
                Dim i As Integer = 0
    
                For Each sbs As String In Line.Split(""""c).ToArray
                    h = sbs
                    For Each item As String In cheackstrings ' Dim cheackstrings() As String = {"As", "If", "In", "Is" , ...}
                        h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower & " ", " " & item & " "), (Convert.ToString("""") & sbs) + """")
    
                        If Not Regex.Match(h, "[A-Za-z0-9]" & item.ToLower & " ", RegexOptions.IgnoreCase).Success Then
                            h = If(i Mod 2 = 0, h.Replace(item.ToLower & " ", item & " "), (Convert.ToString("""") & sbs) + """")
                        End If
                        If Not Regex.Match(h, " " & item.ToLower & "[A-Za-z0-9]", RegexOptions.IgnoreCase).Success Then
                            h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower, " " & item), (Convert.ToString("""") & sbs) + """")
                        End If
    
    
                    Next
                    c += h
                    'for the every odd value of i "word" is within single quotes
                    i += 1
                Next
    
                lines(lnNum) = c
    
    
                lnNum += 1
            Next
            Textbox3.Text = Join(lines, vbCrLf)
        End Sub
    Last edited by Giorgos_xou; Jun 19th, 2015 at 01:51 PM. Reason: i had some wrongs

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Problem Detecting words in Lowercase

    Why don't you tell us what it is that you're trying to do, there may be a better solution that what you're trying.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    i am trying to detect all "cheackstrings()" words in lowercase in textbox3.Text and replace them with cheackstrings() words.

  4. #4
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Problem Detecting words in Lowercase


  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    i am trying to detect all "cheackstrings()" words in lowercase in textbox3.Text and replace them with cheackstrings() words but not inside " " . i am doing this the problem is when i find a line like this ...doesnt change

    green = space
    red = cheackstrings() word
    gray = anything
    Last edited by Giorgos_xou; Jun 19th, 2015 at 02:18 PM.

  6. #6

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    i am using... check the code at first post

  8. #8
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Problem Detecting words in Lowercase

    But you are not. Chucking code from the internet from classes you have not studied is not going to help you. Regex takes years to learn.

  9. #9
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by ident View Post
    But you are not. Chucking code from the internet from classes you have not studied is not going to help you. Regex takes years to learn.
    I disagree. Sure regex is complicated, but it doesn't take you year(s) to learn. It took me around a month to finally learn and understand the basics of regex.
    If you find my contributions helpful then rate them.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by ident View Post
    But you are not. Chucking code from the internet from classes you have not studied is not going to help you. Regex takes years to learn.

    if you dont see were i am using regex you need to visit an ophthalmologists .... are you kidding me !?! i am creating a freaking complicated IDE and you are telling me that i dont know how to use regex and that i am Chucking code from the internet ..... -_- .... i asked for help , not for criticism...
    Last edited by Giorgos_xou; Jun 20th, 2015 at 07:50 AM.

  11. #11
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Problem Detecting words in Lowercase

    I'm still not 100% sure what it is that you want, but take a look at this example:
    Code:
    Option Strict On
    Option Explicit On
    Module Module1
    
        Sub Main()
            'Declare the various VB.Net types
            Dim types() As String = {"Boolean", "Byte", "Char", "Date", "DateTime", "Decimal", "Double", "Integer", "Int32", "Long", "Int64", "Object", "SByte", "Short", "Int16", "Single", "String", "UInteger", "UInt32", "ULong", "UInt64", "UShort", "UInt16"}
    
            'Read the desired source code and split it by a space while removing any empty entries
            Dim tokens() As String = Console.ReadLine().Split({" "}, StringSplitOptions.RemoveEmptyEntries)
    
            'Loop through each item in the token array
            For x As Integer = tokens.Length - 1 To 0 Step -1
                'Get the current token
                Dim token As String = tokens(x)
    
                'Check if there is a value in the types array that matches the token, regardless of casing
                Dim type As String = types.SingleOrDefault(Function(t) String.Compare(t, token, True) = 0)
    
                'If the type is something the set the current token to the type
                If type IsNot Nothing Then
                    tokens(x) = type
                End If
            Next
    
            'Display the reformatted source
            Console.WriteLine(String.Join(" ", tokens))
            Console.ReadLine()
        End Sub
    
    End Module
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  12. #12
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by Giorgos_xou View Post
    if you dont see were i am using regex you need to visit an ophthalmologists .... are you kidding me !?! i am creating a freaking complicated IDE and you are telling me that i dont know how to use regex and that i am Chucking code from the internet ..... -_- .... i asked for help , not for criticism...
    You say you are creating an IDE like some snobby professional. I was offering advice. No you have not studied regex. Two lines next to each other the first you create an array(calling toarray which it already is) and right under that you split a textbox by vbnewline.... How could you not know each line is the same yet one is nearly correct and the other so wrong.

    Regex you submit both upper and lower case in the pattern yet you add the over load ignore case... You are already comparing both cases. It gets worse you call tolower. Why ignore case(twice) and call tolower which is One case?(lower.)

    Quote Originally Posted by Toph View Post
    I disagree. Sure regex is complicated, but it doesn't take you year(s) to learn. It took me around a month to finally learn and understand the basics of regex.
    Yes you can learn basics. How ever was not the last time we spoke it was a pointer on your regex? Believe it takes years. Four years i have studied regex and would no way call my self an expert.

  13. #13
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by ident View Post
    Yes you can learn basics. How ever was not the last time we spoke it was a pointer on your regex? Believe it takes years. Four years i have studied regex and would no way call my self an expert.
    Last time we spoke, you didn't specially point out my regex exp. You just pointed out how the Regex Exp I wrote wouldn't be suited for matching Ipv6 addresses, whereas the Reg exp only matched Ipv4.

    But I do agree, regex is complicated thing to use, but it can be mastered, but that all depends on how often you use it and study it. To master regex it's better to understand how they work behind the scenes like how they work using Finite State Automatons. But I'm sure you're aware of that.
    If you find my contributions helpful then rate them.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by dday9 View Post
    I'm still not 100% sure what it is that you want, but take a look at this example:
    Code:
    Option Strict On
    Option Explicit On
    Module Module1
    
        Sub Main()
            'Declare the various VB.Net types
            Dim types() As String = {"Boolean", "Byte", "Char", "Date", "DateTime", "Decimal", "Double", "Integer", "Int32", "Long", "Int64", "Object", "SByte", "Short", "Int16", "Single", "String", "UInteger", "UInt32", "ULong", "UInt64", "UShort", "UInt16"}
    
            'Read the desired source code and split it by a space while removing any empty entries
            Dim tokens() As String = Console.ReadLine().Split({" "}, StringSplitOptions.RemoveEmptyEntries)
    
            'Loop through each item in the token array
            For x As Integer = tokens.Length - 1 To 0 Step -1
                'Get the current token
                Dim token As String = tokens(x)
    
                'Check if there is a value in the types array that matches the token, regardless of casing
                Dim type As String = types.SingleOrDefault(Function(t) String.Compare(t, token, True) = 0)
    
                'If the type is something the set the current token to the type
                If type IsNot Nothing Then
                    tokens(x) = type
                End If
            Next
    
            'Display the reformatted source
            Console.WriteLine(String.Join(" ", tokens))
            Console.ReadLine()
        End Sub
    
    End Module
    Thanks you dday9 , it works but there are some problems Name:  Tb4M4G5.png
Views: 143
Size:  4.2 KB i dont wont words inside " " be changed and when there is comma after Type it also needs to be changed (that was my problem in my code comma )

  15. #15
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Problem Detecting words in Lowercase

    You could fix the comma issue by adding a comma to the separator parameter for the Split method:
    Code:
    Dim tokens() As String = Console.ReadLine().Split({" ", ","}, StringSplitOptions.RemoveEmptyEntries)
    However, when you join the array back the only separator I'm using is the blank space so it would replace any commas with a blank space. This doesn't address escaping the quotes though...

    The more I keep thinking about your requirements, the more I lean towards a parser. However, a parser is not simple to build by scratch.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  16. #16
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Problem Detecting words in Lowercase

    OP read up on Backus Naur Form. It's how language/syntax is defined in computing language. Have a look at that and see if that helps.
    If you find my contributions helpful then rate them.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by ident View Post
    You say you are creating an IDE like some snobby professional. I was offering advice. No you have not studied regex. Two lines next to each other the first you create an array(calling toarray which it already is) and right under that you split a textbox by vbnewline.... How could you not know each line is the same yet one is nearly correct and the other so wrong.

    Regex you submit both upper and lower case in the pattern yet you add the over load ignore case... You are already comparing both cases. It gets worse you call tolower. Why ignore case(twice) and call tolower which is One case?(lower.)



    Yes you can learn basics. How ever was not the last time we spoke it was a pointer on your regex? Believe it takes years. Four years i have studied regex and would no way call my self an expert.

    first of all i didnt say that i am a professional and i cant be at the age of 17 ... Also i have reason i use for each vbnewline , because i want to check each line ..... and if you had seen the screenshot (i am sure you didnt see because you dont have visit an ophthalmologists yet .... ) you would see something .... THIS ---> Attachment 127743 "just for testing code is here " i had promised to send the fixed ide to someone (you dont need to know who is) next day and i didnt care about the syntax of the code i cared only if it will work so i tested at Picturebox2.Click Event and i wrote a code in some minutes without even testing it as many times needed .... so don't judge before you know

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by dday9 View Post
    You could fix the comma issue by adding a comma to the separator parameter for the Split method:
    Code:
    Dim tokens() As String = Console.ReadLine().Split({" ", ","}, StringSplitOptions.RemoveEmptyEntries)
    However, when you join the array back the only separator I'm using is the blank space so it would replace any commas with a blank space. This doesn't address escaping the quotes though...

    The more I keep thinking about your requirements, the more I lean towards a parser. However, a parser is not simple to build by scratch.

    dday9 check out my code at my first post i am skipping quotes... Name:  PFJqPnM.jpg
Views: 102
Size:  15.5 KB

  19. #19
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by Giorgos_xou View Post
    first of all i didnt say that i am a professional and i cant be at the age of 17 ... Also i have reason i use for each vbnewline , because i want to check each line ..... and if you had seen the screenshot (i am sure you didnt see because you dont have visit an ophthalmologists yet .... ) you would see something .... THIS ---> Attachment 127743 "just for testing code is here " i had promised to send the fixed ide to someone (you dont need to know who is) next day and i didnt care about the syntax of the code i cared only if it will work so i tested at Picturebox2.Click Event and i wrote a code in some minutes without even testing it as many times needed .... so don't judge before you know
    you missed what i said. i doubt you wrote any of that.

  20. #20
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Problem Detecting words in Lowercase

    you do realise regexpert you only check for one char/number?

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by ident View Post
    you do realise regexpert you only check for one char/number?
    if you really love so much to criticising codes then just wait until August - Octomber my ide will be Open source ..... what i have realise, is that you are really annoying

  22. #22
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Problem Detecting words in Lowercase

    ok? btw you now that theme you use

  23. #23
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by dday9 View Post
    The more I keep thinking about your requirements, the more I lean towards a parser. However, a parser is not simple to build by scratch.
    I'd agree with dday on that.


    However, if you want to stick with your current code, then a couple of points:
    (with apologies for my forced formatting of the post. The handling of images
    on this forum is dire, IMO)

    First, I tested your code with
    dim objects as object, objectsa as object
    and my results differed from yours in that the last object didn't end up with
    a capital O. That's because my input didn't end with a space character. Are you forcing the
    addition of space characters to the end of all your lines somewhere else in your code?

    Second, surely the fix for this is simply to add a check for keywords that are followed
    by a comma, or am I over simplifying the problem here?
    Code:
    For Each sbs As String In Line.Split(""""c).ToArray
        h = sbs
        For Each item As String In cheackstrings ' Dim cheackstrings() As String = {"As", "If", "In", "Is" , ...}
    
            h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower & " ", " " & item & " "), (Convert.ToString("""") & sbs) + """")
            h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower & ",", " " & item & ","), (Convert.ToString("""") & sbs) + """")
    
            If Not Regex.Match(h, "[A-Za-z0-9]" & item.ToLower & " ", RegexOptions.IgnoreCase).Success Then
                h = If(i Mod 2 = 0, h.Replace(item.ToLower & " ", item & " "), (Convert.ToString("""") & sbs) + """")
            End If
            If Not Regex.Match(h, " " & item.ToLower & "[A-Za-z0-9]", RegexOptions.IgnoreCase).Success Then
                h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower, " " & item), (Convert.ToString("""") & sbs) + """")
            End If
    
    
        Next
        c += h
        'for the every odd value of i "word" is within single quotes
        i += 1
    Next
    Lastly, I notice that in the first image of your IDE all your keywords are colour coded blue.
    Does another part of your code do that? If so, would it not be an idea to capitalise
    the keywords at the same time you colour code them?

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by Inferrd View Post
    I'd agree with dday on that.


    However, if you want to stick with your current code, then a couple of points:
    (with apologies for my forced formatting of the post. The handling of images
    on this forum is dire, IMO)
    Sorry I didnt know ...

    Quote Originally Posted by Inferrd View Post
    First, I tested your code with
    dim objects as object, objectsa as object
    and my results differed from yours in that the last object didn't end up with
    a capital O. That's because my input didn't end with a space character. Are you forcing the
    addition of space characters to the end of all your lines somewhere else in your code?
    you are right ... accidentally i had two spaces after last object at this line...

    Quote Originally Posted by Inferrd View Post
    Second, surely the fix for this is simply to add a check for keywords that are followed
    by a comma, or am I over simplifying the problem here?
    Code:
    For Each sbs As String In Line.Split(""""c).ToArray
        h = sbs
        For Each item As String In cheackstrings ' Dim cheackstrings() As String = {"As", "If", "In", "Is" , ...}
    
            h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower & " ", " " & item & " "), (Convert.ToString("""") & sbs) + """")
            h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower & ",", " " & item & ","), (Convert.ToString("""") & sbs) + """")
    
            If Not Regex.Match(h, "[A-Za-z0-9]" & item.ToLower & " ", RegexOptions.IgnoreCase).Success Then
                h = If(i Mod 2 = 0, h.Replace(item.ToLower & " ", item & " "), (Convert.ToString("""") & sbs) + """")
            End If
            If Not Regex.Match(h, " " & item.ToLower & "[A-Za-z0-9]", RegexOptions.IgnoreCase).Success Then
                h = If(i Mod 2 = 0, h.Replace(" " & item.ToLower, " " & item), (Convert.ToString("""") & sbs) + """")
            End If
    
    
        Next
        c += h
        'for the every odd value of i "word" is within single quotes
        i += 1
    Next
    i know it is too simply to add a check for keywords that are followed
    by a comma, i was just confused and i was in panic because i had promised to send the fixed ide next day (to someone)
    Quote Originally Posted by Inferrd View Post
    Lastly, I notice that in the first image of your IDE all your keywords are colour coded blue.
    Does another part of your code do that? If so, would it not be an idea to capitalise
    the keywords at the same time you colour code them?
    all keywords capitalise automatically when user is typing but sometimes , like when you copy paste code with lowercase keywords (or ...) it doesnt detect it so i had to use this code when user compiled the application just for checking the code

    also thanks you all for helping me (i finally find a solution in some ways not the best but it does the work)
    Last edited by Giorgos_xou; Jun 22nd, 2015 at 07:31 AM.

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Location
    Greece
    Posts
    16

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by ident View Post
    you do realise regexpert you only check for one char/number?
    Yes i realise it ... i have reason i check only one char/number becasue i dont care about the whole word, if cared i would use this "([A-Za-z0-9]+)"

    Quote Originally Posted by ident View Post
    ok? btw you now that theme you use
    Yes i Know .... but in my IDE or in Visual Studio ? in VS i use the Dark theme (because at night even if i use f.lux[software] my eyes ...) or as someone call it, the Dracula theme , in my IDE
    i use something like the Light Theme ....
    Last edited by Giorgos_xou; Jun 22nd, 2015 at 07:33 AM.

  26. #26
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Problem Detecting words in Lowercase

    Quote Originally Posted by Giorgos_xou View Post
    Sorry I didnt know ...
    Not your fault . it's the forum software. Large images added as attachments are shrunk to the point that their content often becomes unrecognisable. Large images that are in-lined lead to the whole thread's formatting becoming uncomfortably wide, at least in my browser.

    This is one more reason why code should never be posted as an image. Always copy and paste your code from the VS IDE, and place between suitable code tags.


    Quote Originally Posted by Giorgos_xou View Post
    i know it is too simply to add a check for keywords that are followed
    by a comma, i was just confused and i was in panic because i had promised to send the fixed ide next day (to someone)
    Wasn't a criticism. My fear is that I am looking at your problem too simplistically, and that what I have suggested may possibly fail in some circumstance I haven't considered.

    Quote Originally Posted by Giorgos_xou View Post
    all keywords capitalise automatically when user is typing but sometimes , like when you copy paste code with lowercase keywords (or ...) it doesnt detect it so i had to use this code when user compiled the application just for checking the code
    Good point. That's an example of one of those circumstances I haven't considered.

    Quote Originally Posted by Giorgos_xou View Post
    also thanks you all for helping me (i finally find a solution in some ways not the best but it does the work)
    You're welcome. I hope it continues to work as expected .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width