There is a string, for example, this: String someText = "qdvbText." How can I count the number of characters in this line? But there is a condition: you only need to count the characters in the word Text , i.e. to the point. There is also a variable, for example: String firstchar = "T", i.e. it stores the first character in a word whose characters need to be counted. Thus, it is necessary to count the number of characters to a point, but including this first known character, i.e. variable firstchar.

    1 answer 1

    Here is the code that cuts out the line you need:

     String someText = "qdvbText."; String firstchar = "T"; String resultStr = str.substring(str.indexOf(firstchar), str.indexOf('.')); 

    And how to count the number of characters in the line, I think you will not be difficult. :)

    • > str.indexOf (firstchar) + 1 no need to do +1 - andreich
    • Right remark! Right now update :) - MarinaVoyin