How to count the string characters in a JSP ?

Hello,

I have the following code in my JSP -

  if (total_path.startsWith("ost_vexdev_selects")) {
        s_partial_path = total_path.substring(total_path.indexOf("osts_season/System/AppilcationData/")+ 44 );
    } else {
        s_partial_path = total_path.substring(total_path.indexOf("osts_season/System/AppilcationData/")+ 36 );
    }


I would like to know how to change this code so instead of codign - "ost_vexdev_selects"  just check for "_selects " in a string

And instead of coding - 44 or 36  - I get that count from some java api function  like indeof or someting ... ?

Please advise..

Thanks!
sdesarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tomgalloCommented:
-To count the characters of a string use: lenght()
ie: total_path.lenght();

-For the if sentence use:
if(total_path.lastIndexOf("_selects")!=-1)

Hope that helps
-tom
0
sdesarAuthor Commented:
I need to get the length of this string = osts_season/System/AppilcationData/

This is the error I got ..

int cannot be dereferenced
          s_partial_path = total_path.substring(total_path.indexOf("osts_season/System/AppilcationData/").length() );


any suggestions ...
0
tomgalloCommented:
The error lies here:

indexOf() always returns a int... not a string, you can't do indexOf().lenght(), beacuse you only can take the lenght of a string (not an integer).

to get the length of that string do:
String dummy = new String("osts_season/System/AppilcationData/");
dummy.lenght();

The second part: I don't understand what you want to do but I think is almost like this:
s_partial_path = total_path.substring(total_path.indexOf(dummy)+dummy.lenght());

Clarify this for me!
-tom

 
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

sdesarAuthor Commented:
Oh Thanks .. I got it  
s_partial_path = total_path.substring(total_path.indexOf(dummy)+dummy.lenght());


Also one more question
I have a string osts_season_selects.
I just want it to return "osts_season" without the _selects

any suggestions...
0
sdesarAuthor Commented:
One last question .

This is the string
"osts_season_selects"
I just want it to return
"osts_season" without the "_selects"

Please advise .. eagerly awaiting suggestions..
0
sdesarAuthor Commented:
I figured out the answer to the above question.

One last question ........
ost_visdev_selects/System/Application Data/Elements/osts_season/spot/characters/


I need to get "osts_season" from the above string... which should always be after "Elements/ " and end at "/" please advise

eagerly awaitng an answer

Thanks!
0
tomgalloCommented:
You should use aString.substring(int beginIndex, int endIndex)
To retreive the beginIndex you can use lastIndexOf(aString),
for the endIndex use indexOf("/",lastIndexOf(aString))

For more reference all the String class is in:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

Also you can use String dummy[] = aString.split("/") and search the first index after "Elements"'

-tom
0
sdesarAuthor Commented:
Thanks for the above I implemented it and I print the dummy[3] - it returns osts_season

I think this is a last question ..
This is the string
ost_visdev_selects/System/Application Data/Elements/osts_season/spot/characters/

and I want it to return everyting after - Application Data

Please advise.
0
tomgalloCommented:
If you do a split('Application Data') the [0] index is all the string before the first ocurrence of "Application Data"
0
tomgalloCommented:
Sorry I misread your question...

This is the answer: I suppose that your string is in aString variable,

aString.substring(aString.indexOf("Application Data")+16,aString.length());

All the answers to your questions are in the link that I posted earlier:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

Hope this helps,
-tom
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sdesarAuthor Commented:
Thanks for the answers.
HEre are the excellent points
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.