0

need to separate the string,i need to separate it.The String is dynamically add.

For Example

1.String a="C:\Wowza Media Systems\Wowza Media Server 2.2.3\content\user2\weight.mp4" 

i need to separate it user2

2. String a="C:users\Wowza Media Systems\Wowza Media Server 2.2.3\content\user2\sample.flv"

So i added the value dynamically for a, but i need to separate the string before weight.mp4 after content .

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
JavaH
  • 427
  • 2
  • 11
  • 29
  • 2
    What do you need to do to the String? – SJuan76 Sep 05 '12 at 10:33
  • i need to get the path of the video – JavaH Sep 05 '12 at 10:35
  • See [this answer](http://stackoverflow.com/a/12277301/1103412) to a similar question here on SO. – Dušan Rychnovský Sep 05 '12 at 10:37
  • kindly See my questions clearly each and every time my string s differ according to this,How can i separate,from this http://stackoverflow.com/questions/12277246/small-problems-splitting-a-string/12277301#12277301 question,the string is static not dynamic – JavaH Sep 05 '12 at 10:42
  • I'm not sure if I correctly understood your question but I thought you needed to extract the name of the folder in which the file (directly) resided. If that's the case, you could use the same approach as T.Grottker described in his answer to the other question. You might also use the [File class](http://docs.oracle.com/javase/1.4.2/docs/api/java/io/File.html) to easily extract the folder name. – Dušan Rychnovský Sep 05 '12 at 10:50

5 Answers5

1

You Can approach like also..

String s="C:/Wowza Media Systems/Wowza Media Server 2.2.3/content/user2/weight.mp4";
String strArray[]=s.split("/"); 
String fileName = strArray[strArray.length-1]; /*weight.mp4*/
int index = s.indexOf(fileName); 
String path = s.substring(0,index) /*C:/Wowza Media Systems/Wowza Media Server 2.2.3/content/user2/*/
Sivaraman
  • 61
  • 7
0

Are tried something like this?

a = a.replace("users", "");

It's kinda hard for me to explain because i don't know to much what are you trying to do. Is it only avoiding "users" or adding or you try to do something more?

grachol
  • 82
  • 1
  • 7
  • hai grachol,,,i need to separate the string before weight.mp4 after *content* .thats my requirement – JavaH Sep 05 '12 at 10:43
0

You just want to substring the sequence between two last slashes. Look at methods 'lastIndexOf' and 'substring' of String class.

Andrey Atapin
  • 7,745
  • 3
  • 28
  • 34
0

If I understood you correctly you want to fetch the file name from that String. If so:

If you have your String a defined like this:

String a="C:\\Wowza Media Systems\\Wowza Media Server 2.2.3\\content\\user2\\weight.mp4"

try the code:

String[] split = a.split("\\");
String file = null;
if(split.length!=0) file=split[split.length-1];
System.out.println(file);
norbitheeviljester
  • 952
  • 1
  • 6
  • 17
0
String end = a.substring(a.lastindexof("\\"),a.length); // <- get the end
String tmp = a.substring(0,a.lastindexof("\\"));  // <- get the rest
String start = tmp.substring(0,a.lastindexof("\\"); // <- get the start

I'm shure the code above have some syntax errors and in the first line you have to add 1 to the lastindexof perhaps. But it gives you an idea to solve your problem.

JackTools.Net
  • 734
  • 6
  • 13