locked
How to detect string start with capital letter or small RRS feed

  • Question

  • User972064672 posted

    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;
    }

    Sunday, February 17, 2019 11:41 AM

Answers

  • User-1174608757 posted

    Hi Rakib Abmed,

    According to your description, I have made a sample here. I suggest  you to use substring() method to get the part of the line. Substring() could get the part of the string,in this case,you could .substring(0,5) to get the first six digits of the string,then you could judge the string you get  is "ORDINE" or "ordine"or "other". Here is the demo , I hope it could help you.

    aspx:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      
        <title></title>
       
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="check" OnClick="Button1_Click" />
            </div>
        </form>
    </body>
    </html>
    

    code behind:

    public partial class ordine : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                var str = TextBox1.Text;
                if (str.Length >= 6)// make sure the text is longer than 6 size. 
                {
                    string str1 = TextBox1.Text.Substring(0, 5); // get the first six digits of text
                    if (str == "ORDINE")
                    {
                        Response.Write("start with capital ordine ");
    
                    }
                    else if (str == "ordine")
                    {
    
                        Response.Write("start with lowercase ordine");
                    }
                    else
                    {
                        Response.Write("is not capital or lowercase");
    
                    }
    
    
    
                }
                else
                {
    
                    Response.Write("is not capital or lowercase");
                }
               
            }
        }

    You could see as below:

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 18, 2019 6:33 AM

All replies

  • User-1174608757 posted

    Hi Rakib Abmed,

    According to your description, I have made a sample here. I suggest  you to use substring() method to get the part of the line. Substring() could get the part of the string,in this case,you could .substring(0,5) to get the first six digits of the string,then you could judge the string you get  is "ORDINE" or "ordine"or "other". Here is the demo , I hope it could help you.

    aspx:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      
        <title></title>
       
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="check" OnClick="Button1_Click" />
            </div>
        </form>
    </body>
    </html>
    

    code behind:

    public partial class ordine : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                var str = TextBox1.Text;
                if (str.Length >= 6)// make sure the text is longer than 6 size. 
                {
                    string str1 = TextBox1.Text.Substring(0, 5); // get the first six digits of text
                    if (str == "ORDINE")
                    {
                        Response.Write("start with capital ordine ");
    
                    }
                    else if (str == "ordine")
                    {
    
                        Response.Write("start with lowercase ordine");
                    }
                    else
                    {
                        Response.Write("is not capital or lowercase");
    
                    }
    
    
    
                }
                else
                {
    
                    Response.Write("is not capital or lowercase");
                }
               
            }
        }

    You could see as below:

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 18, 2019 6:33 AM
  • User972064672 posted

    Thanks a lot

    Monday, February 18, 2019 2:23 PM