skip to Main Content

Hi i want to know how to get first 25 characters from Long string value. Example i have string value like
“Clamp-on Injection probe Instrumentation” now i want to get the first 25 characters from this string.And also i want to show the whole string value in Tool Tip.

My code

string val1 ="Clamp-on Injection probe Instrumentation"
 string val2 =val1.Substring(25, Math.Min(val1 .Length, maxLength));

I have tried the above code.And correct my code if i am wrong and also tell me how to show the whole string value in tool tip .Kindly any one help me resolve this issue.Thanks.

2

Answers


  1. Below code should get you first 25 characters of string :

    string val1 = "Clamp-on Injection probe Instrumentation";
    string val2 = val1.Substring(0, 25);
    

    In your html:

    @Html.Label("Your label string ",new { title="tooltip string"});
    
    Login or Signup to reply.
  2. I think using just CSS would do it, try building a html like this:

    <h4 title="Clamp-on Injection probe Instrumentation">
        Clamp-on Injection probe Instrumentation
    </h4>
    

    And add this kind of CSS:

    h4{
      width: 50px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    

    This would make the text that doesn’t fit within 50px to be hidden using ellipsis ..., and will show the full tooltip since the title contains the full text.

    Hope it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search