-
Jun 19th, 2015, 01:43 PM
#1
Thread Starter
Junior Member
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
-
Jun 19th, 2015, 01:46 PM
#2
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.
-
Jun 19th, 2015, 01:58 PM
#3
Thread Starter
Junior Member
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.
-
Jun 19th, 2015, 01:59 PM
#4
Re: Problem Detecting words in Lowercase
-
Jun 19th, 2015, 02:14 PM
#5
Thread Starter
Junior Member
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.
-
Jun 19th, 2015, 02:18 PM
#6
Re: Problem Detecting words in Lowercase
-
Jun 19th, 2015, 02:24 PM
#7
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
i am using... check the code at first post
-
Jun 19th, 2015, 05:05 PM
#8
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.
-
Jun 19th, 2015, 05:15 PM
#9
Re: Problem Detecting words in Lowercase
Originally Posted by ident
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.
-
Jun 20th, 2015, 07:43 AM
#10
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by ident
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.
-
Jun 21st, 2015, 11:30 AM
#11
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
-
Jun 21st, 2015, 11:49 AM
#12
Re: Problem Detecting words in Lowercase
Originally Posted by Giorgos_xou
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.)
Originally Posted by Toph
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.
-
Jun 21st, 2015, 12:06 PM
#13
Re: Problem Detecting words in Lowercase
Originally Posted by ident
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.
-
Jun 21st, 2015, 12:09 PM
#14
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by dday9
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 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 )
-
Jun 21st, 2015, 12:20 PM
#15
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.
-
Jun 21st, 2015, 12:38 PM
#16
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.
-
Jun 21st, 2015, 12:58 PM
#17
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by ident
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
-
Jun 21st, 2015, 01:03 PM
#18
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by dday9
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...
-
Jun 21st, 2015, 06:41 PM
#19
Re: Problem Detecting words in Lowercase
Originally Posted by Giorgos_xou
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.
-
Jun 21st, 2015, 06:43 PM
#20
Re: Problem Detecting words in Lowercase
you do realise regexpert you only check for one char/number?
-
Jun 21st, 2015, 07:57 PM
#21
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by ident
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
-
Jun 21st, 2015, 08:08 PM
#22
Re: Problem Detecting words in Lowercase
ok? btw you now that theme you use
-
Jun 22nd, 2015, 06:15 AM
#23
Re: Problem Detecting words in Lowercase
Originally Posted by dday9
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 withdim 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?
-
Jun 22nd, 2015, 07:21 AM
#24
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by Inferrd
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 ...
Originally Posted by Inferrd
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...
Originally Posted by Inferrd
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)
Originally Posted by Inferrd
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.
-
Jun 22nd, 2015, 07:29 AM
#25
Thread Starter
Junior Member
Re: Problem Detecting words in Lowercase
Originally Posted by ident
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]+)"
Originally Posted by ident
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.
-
Jun 22nd, 2015, 07:42 AM
#26
Re: Problem Detecting words in Lowercase
Originally Posted by Giorgos_xou
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.
Originally Posted by Giorgos_xou
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.
Originally Posted by Giorgos_xou
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.
Originally Posted by Giorgos_xou
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|