-
Help me to Substring pls!!
Hi all,
I hv a problem about substring method, I want to seperate data that I hv already got from db. An example of data as below message.
Data:
pic1.jpg,read1.pdf,abc.jpg,you_to_me.txt,
After I received data from db, I would like to delimited each file name by "," (comma) then displays as the below expected result
Expected result:
tmp1 = pic.jpg
tmp2= read.pdf
tmp3 = abc.jpg
tmp4= you_to_me.txt
Pls kindly help me. thank you very much
-
your using the wrong method. Use the split method.
example:
String[] splitData;
String data = "data1,data2,data3,data4";
splitData = data.split(",");
create an array variable that will hold the deliminated data. Then when u need the data you simply use it like this.
for (int i=0; i <= splitData.lenght;i++)
{
System.out.println(splitData[i]);
}
Hope that helps.
-
Thank you very much "Major" but I hv another problem, I cannot this method because there is a variable of data. I mean simetime my data has 4 filenames somtime 10 or more, it is not stable if I use String array I will seperate only 4 filenames....
can i specific size of array?
-
The Scanner class will create an array of all of the tokens - dynamically, as many elements as there are tokens. I believe that split() will do the same.
-
hi pearwarin, u dont need to set how many array u need in advance, u just decalre an instance of an array variable and not set it size, the split method will then allocate the size. The scanner class is also an option as mentioned by nspils, but it is available for java 5 i believe.
-
Ok I got it ! Thank you very much
Similar Threads
-
Replies: 0
Last Post: 11-29-2001, 09:07 AM
-
Replies: 1
Last Post: 06-13-2001, 09:03 AM
-
By Mehdi Mousavi in forum Database
Replies: 0
Last Post: 11-22-2000, 03:42 PM
-
Replies: 1
Last Post: 08-30-2000, 12:37 PM
-
Replies: 1
Last Post: 08-20-2000, 01:53 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks