Check if string start with capital or small letter in C# and VB.Net

Last Reply 7 months ago By pandeyism

Posted 7 months ago
I have a same string Called ORDINE and ordine what i want to is to check if it is start with capital ordine or lowercase ordine. i want to do something below
 
if (line.Replace(".", "").Trim().StartsWith("ORDINE"))
{ 
    skipLine = 3;
    continue;
}

or 

if (line.Replace(".", "").Trim().StartsWith("ordine"))
{ 
    skipLine = 1;
    continue;
}

 

You are viewing reply posted by: pandeyism 7 months ago.
Posted 7 months ago

Hi rakibxl,

Please refer below code for checking upper and lower letter.

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    string value = "oRDINE";
    string line = "";
    int skipLine = 0;
    bool a = StartLetterCheck(value);
    if (a == true)
    {
        if (line.Replace(".", "").Trim().StartsWith("ORDINE"))
        {
            skipLine = 3;
        }
    }
    else
    {
        if (line.Replace(".", "").Trim().StartsWith("ordine"))
        {
            skipLine = 1;
        }
    }
}

public bool StartLetterCheck(string word)
{
    return Enumerable.Range(65, 26).Contains((int)word[0]);
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim value As String = "oRDINE"
    Dim line As String = ""
    Dim skipLine As Integer = 0
    Dim a As Boolean = StartLetterCheck(value)
    If a = True Then
        If line.Replace(".", "").Trim().StartsWith("ORDINE") Then
            skipLine = 3
        End If
    Else
        If line.Replace(".", "").Trim().StartsWith("ordine") Then
            skipLine = 1
        End If
    End If
End Sub
Public Function StartLetterCheck(ByVal word As String) As Boolean
    Return Enumerable.Range(65, 26).Contains(CInt(Val(word(0))))
End Function