none
Using Upper, Lower case and Len functions RRS feed

  • Question

  • Hello,

    I would like to know more about how to use upper, lower, and length (Len) built-in functions effectively.

    For example, finding words that begin with capital letters.

    This would be useful for querying searches.

    Regards,

    JohnDBCTX


    jp

    Tuesday, June 12, 2018 3:57 AM

Answers

  •             If Char.IsUpper(strContents, 0).Equals(True) Then
                    txtDenotations.Text &= strContents
                End If

    I added the equals method as true and it worked fine, but it worked only in sentences.

    Regards,

    JohnDBCTX


    jp

    • Marked as answer by JohnDBCTX Tuesday, June 12, 2018 7:24 AM
    Tuesday, June 12, 2018 7:21 AM

All replies

  • For example, finding words that begin with capital letters.

    See: https://docs.microsoft.com/en-au/dotnet/api/system.char.isupper?view=netframework-4.7_

    For assistance with the other functions use the examples provided in the documentation.   If you have a query about that documentation or the examples, ask a specific question here: it's usually not worthwhile for someone to try to paraphrase the existing documentation without knowing just what you are unsure about.  If you have a particular task, show the code you have created so far and indicate where you are running into a problem. What type of searching are you referring to?

    Tuesday, June 12, 2018 4:44 AM
  • What I have meant is the leftmost position of a string parameter.

    For instance:

    if isupper(len(1, strCapitalized)) then
    	txtBoxOne.text=strCapitalized
    end if

    Would that be correct?

    Regards,

    JohnDBCTX



    jp

    Tuesday, June 12, 2018 6:36 AM
  • What I have meant is the leftmost position of a string parameter.

    For instance:

    if isupper(len(1, strCapitalized)) then
    	txtBoxOne.text=strCapitalized
    end if

    Would that be correct?

    Regards,

    JohnDBCTX



    jp

    Hi

    I think you want:

     If Char.IsUpper(strCapitalized, 0) Then
       txtBoxOne.text = strCapitalized
     End If
    


    Regards Les, Livingston, Scotland

    Tuesday, June 12, 2018 6:59 AM
  •         If InStr(strContents, UCase(strContents), CompareMethod.Binary) = 0 Then
                txtDenotations.Text &= vbNewLine & strContents
            End If

    So far, it returns a sentence; it does not extract words that begin with capital letters.

    Regards,

    JohnDBCTX


    jp


    • Edited by JohnDBCTX Tuesday, June 12, 2018 7:14 AM improved coding
    Tuesday, June 12, 2018 7:12 AM
  •             If Char.IsUpper(strContents, 0).Equals(True) Then
                    txtDenotations.Text &= strContents
                End If

    I added the equals method as true and it worked fine, but it worked only in sentences.

    Regards,

    JohnDBCTX


    jp

    • Marked as answer by JohnDBCTX Tuesday, June 12, 2018 7:24 AM
    Tuesday, June 12, 2018 7:21 AM
  • So far, it returns a sentence; it does not extract words that begin with capital letters

    That code won't extract words that begin with capital letters.  It displays the source text if that text is all upper case - that is, if the text compared to the uppercase version of the text results in a match at character position zero.  It's a very roundabout way of testing if two strings are equal, case sensitive.

    If you want to find words that start with capital letters then you would first break the sentence down into an array of words:
    https://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx

    Then examine each element of the array using Char.IsUpper on the first character:
    https://msdn.microsoft.com/en-us/library/system.char.isupper(v=vs.110).aspx

    (Note that defining a 'word' might not be as simple as it first seems.)

     

    Tuesday, June 12, 2018 7:28 AM
  • Now what about for words?

    Namely, a string parameter that begins with a capital letter and ends with a blank or whitespace.

                Input(1, strContents)
                If Char.IsUpper(strContents, 0).Equals(True) Then
                    txtDenotations.Text &= strContents
                End If
                If Char.IsWhiteSpace(strContents, 0).Equals(True) Then
                    txtDenotations.Text &= strContents
                End If

    I want to combine the two condition blocks into one by using one of those built-in methods:

    Len

    Right

    Left

    It should not be too difficult at all...I believe.

    Regards,

    JohnDBCTX


    jp

    Tuesday, June 12, 2018 7:33 AM
  • Now what about for words?

    Namely, a string parameter that begins with a capital letter and ends with a blank or whitespace.

                Input(1, strContents)
                If Char.IsUpper(strContents, 0).Equals(True) Then
                    txtDenotations.Text &= strContents
                End If
                If Char.IsWhiteSpace(strContents, 0).Equals(True) Then
                    txtDenotations.Text &= strContents
                End If

    I want to combine the two condition blocks into one by using one of those built-in methods:

    Len

    Right

    Left

    It should not be too difficult at all...I believe.

    Regards,

    JohnDBCTX


    jp

    Hi

    No need for any of us to answer your questions as you seem to be doing that by yourself - going by the fact that you have marked your own post as Answer (which it wasn't) and closed this thread.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, June 12, 2018 7:38 AM
    Tuesday, June 12, 2018 7:37 AM
  • Okay, here, I have imported the Word library in Vb.Net

    Imports Microsoft.Office.Interop.Word Private strContents As String Private WrdX As Words 'Needs instantiation prior to compiling

    If WrdX.First.Words(strContents).Equals(True) Then txtDenotations.Text = strContents End If

    I think it would be simpler if I did it that way.  

    Regards,

    JohnDBCTX


    jp

    Tuesday, June 12, 2018 7:57 AM
  • I want to combine the two condition blocks into one by using one of those built-in methods:

    You are just confusing people by marking an answer that doesn't seem to answer anything, changing the description of what you want to do, and suddenly altering the topic to the WORD object model. 

    Do one question at a time. Make sure that you provide sample data and sample results, and start a new question in a new thread.

    I suspect that what you are trying to do in that second condition block is to test the last character of a string for white space.   What is 'Input(1, strContents)' ? Depending on what that does, it might not be possible for the last character to actually be whitespace.   I would recommend writing this code using literals, not user input.

    Tuesday, June 12, 2018 8:57 AM
  • The way to find words beginning with Caps is as follows:

    '  Imports System.Text.RegularExpressions
    
    '  Regular expression built for Visual Basic on: Tue, Jun 12, 2018, 07:24:03 AM
    '  Using Expresso Version: 3.1.6224, http://www.ultrapico.com
    '  
    '  A description of the regular expression:
    '  
    '  Any character in this class: [A-Z]
    '  Any character in this class: [a-z], at least 2 repetitions
    '  
    '
    
    Public Dim MyRegex As Regex = New Regex( _
          "[A-Z][a-z]{2,}", _
        RegexOptions.CultureInvariant _
        Or RegexOptions.Compiled _
        )
    
    
    
    '' Replace the matched text in the InputText using the replacement pattern
    ' Dim result As String = MyRegex.Replace(InputText,MyRegexReplace)
    
    '' Split the InputText wherever the regex matches
    ' Dim results As String() = MyRegex.Split(InputText)
    
    '' Capture the first Match, if any, in the InputText
    ' Dim m As Match= MyRegex.Match(InputText)
    
    '' Capture all Matches in the InputText
    ' Dim ms As MatchCollection = MyRegex.Matches(InputText)
    
    '' Test to see if there is a match in the InputText
    ' Dim IsMatch As Boolean = MyRegex.IsMatch(InputText)
    
    '' Get the names of all the named and numbered capture groups
    ' Dim GroupNames As String() = MyRegex.GetGroupNames()
    
    '' Get the numbers of all the named and numbered capture groups
    ' Dim GroupNumbers As Integer() = MyRegex.GetGroupNumbers()
    
    
    
    Regular expressions are a way of searching text for patterns, your pattern is a word starting with a capital letter.  In your case the example to use would be the MyRegex.Matches(InputText).


    Lloyd Sheen

    Tuesday, June 12, 2018 11:28 AM