This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

substring of file name  RSS feed

 
kfir goldvaser
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

I am trying to get a substring of a file name and I need in specific place.

the name is OS_inshp1_2_6775863_1188132465113_(OS_L_inshp1_292_1188132343)_load.xip

and I would like to know what is the command to get only what in between ()

meaning, to run up to the '(' sign, get the name inside until getting to ')' sign.

thanks for the help
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the API for String.substring() and String.indexOf()
 
kfir goldvaser
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did, but since there could be names with different size, the '(' sign is not in a specific place so i am not sure I can give the place where it starts and stops.
I need some how to run on the string and find where it starts and from there to get the string, I just didnt find how I do it.
appreaciate if you may have an example of how it is written

Thanks
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned by Manuel Leiria , you can use indexOf to find the start and end index and then using substring method of chop out the required portion.
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tech Tip: will give you the position (index) of the char (
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!