Results 1 to 9 of 9

Thread: Can someone explain how to only allow case sensitive in a certain spot of a string?

  1. #1

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Can someone explain how to only allow case sensitive in a certain spot of a string?

    Its specifically for navigation purposes, anything after "/" : http://example.com/ can be case sensitive is what my goal - Anything before the / doesn't need to be capitalized, anything after is case sensitive.


    Thanks for any help!
    Last edited by jdc20181; Dec 15th, 2017 at 02:15 PM.
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  2. #2
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    Are you saying that everything after the "/" needs to be UpperCase and anything before doesnt matter?

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    This question doesn't really make sense. A string cannot be described as case sensitive. A search, or more broadly, an operation can be described as case sensitive. A string is just a series of good old bytes that are interpreted a specific way.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    I think I understand what JDC means. The alphabetic case matters only after the first "/". You could use ToUpper or ToLower to convert the first part to whichever case you prefer, something like this:
    Code:
          Dim sourceString As String = "htTp:\xyz.123"
          Dim parts() As String = sourceString.Split({"\"}, 2, StringSplitOptions.None)
          If parts(0).ToUpper = "HTTP:" Then
             'do this
          Else
             'do that
          End If
    BB

  5. #5

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    To explain better lets say we have a file path and its MondayTuesdayWednesday - as of right now I had it enforcing lowercase, so if you type in MondayTuesdayWednesday, it would go to mondaytuesdaywednesday


    What I am wanting to do is allow http://example.com/MondayTuesdayWednesday, but not allow any part before the "/" to be capital. Because the browser controls, geckofx or even the standard provided by microsoft, do not automatically do this, so if you were to type in FaCeBook.com it would give you an error, or at least I had it happen before.

    Case sensitive "directories" is what I was meaning to get at.

    You are close, @BB as I described better above, I only want the "Directory" part which would be after the last "/"

    btw, you nailed what I was thinking I just didn't understand how to do it with the splitting a string and such, thanks for the snippet I am going to experiment.
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    But then what happens if your user wants to go to a website that's configured for its domain name to always be capitalized a certain way? It's not a recommended practice, but it could happen.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    Here's a small class I just wrote that can do what you ask through a naive tokenization method:-
    vbnet Code:
    1. Imports System.Text
    2.  
    3. Public Class URLStringHelper
    4.     Private Enum CharType
    5.         AlphaNumericChar
    6.         SymbolChar
    7.     End Enum
    8.  
    9.     Private Enum URLSyntax
    10.         HTTP
    11.         ColonSlashSlash
    12.         WWW
    13.     End Enum
    14.  
    15.     Public Shared Function FixURLCase(ByVal url As String) As String
    16.         Dim tokens As String() = GetURLTokens(url)
    17.         Dim newUrl As New StringBuilder
    18.         Dim i As Integer = 0
    19.  
    20.         If tokens(i).ToLower = "http" OrElse tokens(i).ToLower = "https" Then
    21.             newUrl.Append(tokens(i).ToLower)
    22.  
    23.             i += 1
    24.  
    25.             If Not tokens(i) = "://" Then
    26.                 Throw New Exception("Invalid URL")
    27.             End If
    28.  
    29.             newUrl.Append(tokens(i))
    30.             i += 1
    31.         End If
    32.  
    33.         If tokens(i).ToLower = "www" Then
    34.             newUrl.Append(tokens(i).ToLower)
    35.             i += 1
    36.  
    37.             If tokens(i) <> "." Then
    38.                 Throw New Exception("Invalid URL")
    39.             Else
    40.                 newUrl.Append(tokens(i))
    41.                 i += 1
    42.             End If
    43.         End If
    44.  
    45.         'Should be the at the host name
    46.         newUrl.Append(tokens(i).ToLower)
    47.         i += 1
    48.  
    49.         'The dot before .COM or .ORG etc
    50.         If tokens(i) <> "." Then
    51.             Throw New Exception("Invalid URL")
    52.         Else
    53.             newUrl.Append(tokens(i))
    54.             i += 1
    55.         End If
    56.  
    57.         'The suffix of the host name. Eg. COM, ORG, NET etc
    58.         newUrl.Append(tokens(i).ToLower)
    59.         i += 1
    60.  
    61.         If i < tokens.Length - 1 Then
    62.             'The slash before the host's subdirectories or files
    63.             If tokens(i) <> "/" Then
    64.                 Throw New Exception("Invalid URL")
    65.             Else
    66.                 newUrl.Append(tokens(i))
    67.                 i += 1
    68.             End If
    69.  
    70.             'Add all the rest of tokens unchanged
    71.             For x = i To tokens.Length - 1
    72.                 newUrl.Append(tokens(x))
    73.             Next
    74.  
    75.         End If
    76.  
    77.  
    78.  
    79.         Return newUrl.ToString
    80.     End Function
    81.  
    82.  
    83.     Private Shared Function GetURLTokens(ByVal url As String) As String()
    84.  
    85.         Dim currentToken As New List(Of Char)
    86.         Dim tokens As New List(Of String)
    87.  
    88.         Dim mode As CharType = CharType.AlphaNumericChar
    89.  
    90.         For Each c As Char In url.ToCharArray
    91.             If Char.IsLetterOrDigit(c) AndAlso mode = CharType.SymbolChar Then
    92.                 tokens.Add(New String(currentToken.ToArray))
    93.  
    94.                 currentToken = New List(Of Char)
    95.  
    96.                 mode = CharType.AlphaNumericChar
    97.             End If
    98.  
    99.  
    100.             If Not Char.IsLetterOrDigit(c) AndAlso mode = CharType.AlphaNumericChar Then
    101.                 tokens.Add(New String(currentToken.ToArray))
    102.  
    103.                 currentToken = New List(Of Char)
    104.  
    105.                 mode = CharType.SymbolChar
    106.             End If
    107.  
    108.  
    109.             currentToken.Add(c)
    110.  
    111.         Next
    112.  
    113.         tokens.Add(New String(currentToken.ToArray))
    114.  
    115.         Return tokens.ToArray
    116.     End Function
    117.  
    118.  
    119.  
    120. End Class

    Here's an example of it's use:-
    vbnet Code:
    1. '
    2.         Dim urls As New List(Of String)
    3.  
    4.         urls.Add("HTTP://WWW.EXAMPLE.COM")
    5.         urls.Add("HTTPS://WWW.EXAMPLE.COM")
    6.         urls.Add("HTTPS://WWW.EXAMPLE.COM/MONDAYNIGHT/RAW")
    7.         urls.Add("WWW.EXAMPLE.COM")
    8.         urls.Add("HTTP://EXAMPLE.COM")
    9.         urls.Add("HTTP://EXAMPLE.COM/HELPME/INDEX.PHP")
    10.         urls.Add("EXAMPLE.COM/HELPME/INDEX.PHP")
    11.         urls.Add("WWW.EXAMPLE.COM/MONDAYNIGHT")
    12.  
    13.         For Each url In urls
    14.             Debug.WriteLine(URLStringHelper.FixURLCase(url))
    15.         Next

    And the output:-
    Code:
    http://www.example.com
    https://www.example.com
    https://www.example.com/MONDAYNIGHT/RAW
    www.example.com
    http://example.com
    http://example.com/HELPME/INDEX.PHP
    example.com/HELPME/INDEX.PHP
    www.example.com/MONDAYNIGHT
    Notice that it can handle different ways of expressing the host name, with or without the "http" prefix or the "www" prefix or any combination thereof.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    Quote Originally Posted by Sitten Spynne View Post
    But then what happens if your user wants to go to a website that's configured for its domain name to always be capitalized a certain way? It's not a recommended practice, but it could happen.
    Google Chrome, Firefox, Safari, Opera, Internet Explorer/Edge all do this tactic. Older versions of IE do not automatically add http, for example so its the only exception.
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  9. #9

    Thread Starter
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: Can someone explain how to only allow case sensitive in a certain spot of a strin

    Quote Originally Posted by Niya View Post
    Here's a small class I just wrote that can do what you ask through a naive tokenization method:-


    Notice that it can handle different ways of expressing the host name, with or without the "http" prefix or the "www" prefix or any combination thereof.
    Thanks. I will take a closer look and see how this can work out
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

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