substring 2 « substring « Java Data Type Q&A





1. Getting substring    forums.oracle.com

2. help: why using substring    forums.oracle.com

3. Substring Loop - unsure how to do it.    forums.oracle.com

To sum it up a bit more basic, I have to get the user to enter a String (using Scanner class), The string then has to be read back in a loop until the String entered has finished, for example if i entered Scott, it would have to output S:Sc:Sco:Scot:Scott, and each time the letters are read back they have to ...

4. StringTokenizer and substring method    forums.oracle.com

while(hasMoreTokens) { src = nextToken; des = nextToken; cost = nextToken; String a = src + des + cost; } int [] [] array = new int[ i ] [ j ] Since I'm using tokens, I just want to take the cost and put it in a 2D array. Can I use the substring on a.substring (2,3) to get the ...

5. multiple substring    forums.oracle.com

I don't think you need lastIndexOf. You need the indexOf that takes a starting point (otherwise, you always start at the beginning of the String). Then, after the first indexOf(""), start the indexOf("") at part_start_index+15. (You may want to define a constant PART_START_TAG_LENGTH [or whatever name] instead of 15. Easier to know what the 15 means, and easier to change if ...

6. substring problem...    forums.oracle.com

7. how does the substring method work    forums.oracle.com

split public String[] split(String regex) Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex Result ...

8. while loop with substring()    forums.oracle.com

9. Substring function    forums.oracle.com

Hello to all Guys i am trying to use Substring Function but not able to do it properly. I am having a String str="LITTEL BY LITTEL AN ACRON SAID"; The result which i want is that i should get each and every word and i cant use substrin(0,6) then substring(7,8) this i can't use i have to use a for loop ...





10. better way to substring any text    forums.oracle.com

hi.. i have a txt file.which contain lot of data..in the following format i.e RTR0000001H0354 C000000000010000000000063A0000000000000{0000000000063A0000000000060{0000000000003A000000010000000000063A And i have to cut this string in tokens on basis of space(as delimeter) And then extract information from each token by applying substring.. As i know that by using StringTokenizer and subString() i can solve this issue.. But i want to know is it ...

11. Should I use substring or tokenizer? Or something else entirely?    forums.oracle.com

I am a student writing a program that has to read a HTML file and make sure all the delimiters match. I tried substring to locate the indexOf the "<">" but for the whole string, it will only give me the first occurence of each one. My first string could be <BODY>. I tried tokenizer but it pulls everything outside of ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>12. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=1252231&tstart=17580'>Explain the concept of substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I was about to post that I'd bet that even a computer illiterate newb would be able to work out what "substring" meant, then realised I had a real life one sat right here. I explained the concept of "strings" to my completely non-IT literate girlfriend, and asked her what she thought a substring might be. She was spot-on </p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>13. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=1256527&tstart=29565'>how does substring() method works ????</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I'm trying to understand substring() method but doesn't seem to be getting close. The method substring(startIndex,endIndex); so i think in order to get "hell" from the string "hello" then i think i'd need to say substring(0,3) , m i right ?? But the result is not "hell" it's "hel" . I mean what's wrong with it ?? According to my understanding ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>14. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2044292&tstart=9930'>Substring problem. Unable to get the expected value using String.subString</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi, I'm having a string whose value is " n" for example, String s = " n"; Now i want the string "\n" I used all the possibilities of s.subString (0,1) or (1,1) or (1,2) or (0,2) but i couldn't get the expected result "\n" Can anyone please advice how to get the expected result??? Thanks, Kathir </p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>15. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2045872&tstart=12720'>.substring issues</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>16. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2045878&tstart=12750'>Java Substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><br/><br/><style>.example_responsive_1 { width: 320px; height: 100px; }@media(min-width: 500px) { .example_responsive_1 { width: 468px; height: 60px; } }@media(min-width: 800px) { .example_responsive_1 { width: 468px; height: 60px; } }</style><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- java2s --><ins class="adsbygoogle example_responsive_1"style="display:block"data-ad-client="ca-pub-1130008796007602"data-ad-slot="6237403822"data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script><br/><br/></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>17. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2047064&tstart=14910'>Substring problem</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>You should write some tests to confirm that your code is correct. Try to think of lots of different inputs and make sure that the outputs are correct. You can use something like JUnit for this (it's a useful tool to learn) or just write your own if you're a newbie. Asking others to confirm that the code runs correctly is ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>18. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2047065&tstart=14910'>first string is a substring of the second one</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I need to write a User Defined Method which Checks if the first string is a substring of the second one. - Returns 0 if it is not a substring / 1 if it is / -1 if it is a circular substring this is an example of what it should do - abcde is a substring of blkjabcdelkjsd return ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>19. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2051026&tstart=21330'>Possible substring issue, need new eye's for my bug.</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>20. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2051446&tstart=21975'>source code for substring..</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi Experts, I have a requirement like this.. getting a purchase order in the variable PONUM as 00012345/abc i need to suppress all the zeros at the left side and when it reaches / then after the / terminate all the characters and return only the number, the output for the ponumber is 12345. eg: Input : 000123045/xyz Output : 123045 ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>21. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2051490&tstart=22050'>substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Dear flounder, my program will read the file in and store in str. There is no split(delimiter) to determine when i should read new line. So in my case, I will need to split the string control by length. I tested the program after i posted this thread. Indeed the while loop will return false because the str length is larger ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>22. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2058225&tstart=33075'>Java substring....</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>23. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2059190&tstart=34800'>hashtables: how can I get all the keys starting with a substring ?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>24. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2059679&tstart=35685'>Regarding substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi, I am currently using substring to extract part of a word and then compare it with a a predefine value. But when I perform a profiling on it, I notice the substring() is taking up a lot of my processing time. So, I am wondering is there another method that perform the same function as substring() but is faster. Or ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>25. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2060388&tstart=37035'>Substring?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi, I am currently working on a method that will loop through a list of words in a text file. There quite a large number of them. Each word in the text file once loaded, I will used substring to extract a portion of the word out which will be stored separately My question is there any method that will work ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>26. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2060953&tstart=38085'>Create Substring???</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>27. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2064907&tstart=45210'>How to Substring from the last 3rd underscore?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Well, you could use lastIndexOf three times (with the start position option) but I think it looks more like a job for a regular expression (which could also check if the file name has the pattern you're expecting.) You might want a pattern like "[A-Z][0-9]_{6}[A-Z0-9]*_[0-9]\.txt$", depends how much these file names are expected to vary. </p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>28. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2065083&tstart=45540'>Help with substring -</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>This is what i have upto now and i get error message saying "out of bound". I would also like to credit Chris.Brown SPE for this code import java.util.regex.*; import java.io.*; class readlinebyline2 { public static void main(String args[]) { try{ FileInputStream fstream = new FileInputStream("c:/input.doc"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>29. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2070258&tstart=54450'>Read/Find substring/ Write</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>30. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2070579&tstart=54990'>Substring Help</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi , I would appreciate if somebody could help me with this. I have a text file with more than 4000 lines. I need to find a substring of 35 zeros '00000000000000000000000000000000000' and they could be in more than one place. This program should actually read from file to find those substring . If it find 35 zeros i need 10 ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>31. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2072442&tstart=58215'>how to print substring within a string without using StringTokenizer</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>32. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2072919&tstart=59025'>How to get a particular substring?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>33. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2074041&tstart=60885'>Creating a Substring out of String seperated by comma</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi, My requirement is that i have a String with comma seperated value. Say String str=''1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20..............."; In my SQL query I need the following. OR(str1) OR(str2); Where str1 is the first 999 strings from the String str. i.e str1="1,2,3,4................999" and str2="1000,1001.......................1999" How can i do this in java.Can anyone please help me out?? Regards, priya </p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>34. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2074663&tstart=61905'>getting the substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>35. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2075592&tstart=63600'>substring generator</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I am tryung to build a program that will implement a substring generator. It will take a string and generate all substrings. Is this using permuate or what? For instance you take the word sun and some up with s su sun u un and n as substings Any assistance much appreciated Thanks Jonnie </p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>36. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2077434&tstart=66660'>Substring or ...?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hello, i have an interesting question :)) This is example of what i have to do.. From: kudazanovu@gmail.com Sent: Friday, December 28, 2007 9:45 PM To: kudazanovu@igorinjo.com Subject: [2008|cabaretrose] Brzo osvoji 28.12.2007. 20:44:54 Name: Ana Ivanovic Tel: 064/164-37-77 Email: anaaerobic777@yahoo.com Time: 28.12.2007. 20:44:54 From: kudazanovu@gmail.com Sent: Friday, December 28, 2007 9:04 PM To: ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>37. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2078294&tstart=68055'>String method to return subString based on "tags"</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>38. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2091060&tstart=88500'>How to get substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>No probs !!! you can comment on my approach. Basically, I would say it is kind of overkill. - First you check the format of the input String in order to determine whether your process will work. - Then, you split the input in order to extract the right-hand part of "ttl=". - Then you split this part in order to ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>39. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2091098&tstart=88545'>How can I make the substring stays at the same location after modified?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>40. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2092166&tstart=90090'>how to make substring a string in concern with length</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>41. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2095313&tstart=94845'>Help, Substring not working, dont know why...</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I need to load some xml file and extract some data from it. I have this code. I thing that this have to work but havent...it prints input error... Any suggestion? file is opened by this code it works ///// if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(FileChooserDemo.this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); //// /// this doesnt ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>42. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2095909&tstart=95760'>substring questions</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>43. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2096493&tstart=96690'>String.subString</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>i heard that using subString method is String and StringBuffer are slow Where did you hear that? All it does (in sun's implementation) is create a new string object that references the same underlying char array as the original string with a different offset and count. This is done specifically for performance. would iterating the range and appending it to a ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>44. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2097260&tstart=97845'>I have a problem in substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I want to read from a file.The file contain strings like Cpu(s): 0.7% us, 0.7% sy, 0.0% ni, 98.3% id, 0.0% wa, 0.3% hi, 0.0% si I want to take the value 0.7 from the file. so I use substring(9,12) a pgm import java.io.*; class FileRead { public static void main(String args[]) { try{ // Open the file that is the ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>45. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2100581&tstart=103350'>Substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>yes Olew Ur right but when we give the both index for substring (Start and End) then that is much better for getting substring from a string. yeah substring(beginindex) san give the right result in case of deepi Q,but if he/she want to get some substring which is not fisrt 4 or last 4 character then substring(stratindex ,endindex ) is used,thats ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>46. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2103099&tstart=107430'>adding color into substring</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>I am trying to color suffix and prefix of strings. For example, I would like to change the suffix substring "tion" in the string "position" to blue or red. It seems like there will be straight forward way to do so, but I could not fine it. I tried doing it using the graphics functions, g.drawString, but then I could not ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>47. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2104714&tstart=110040'>substring a string in the reverse direction</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>48. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2105151&tstart=110775'>Wrong Answer for substring question?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>This is the question from one of Sun's e-Practice exams. I am only posting it because I believe the answer is wrong. QUESTION: A text field in a GUI allows a user to type in a string, pNum, that represents a telephone number in the following format: AAA-PPP-NNNN; where A, P, and N are digits. Assume that this string format has ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>49. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2107088&tstart=113850'>Problem Related substring() function</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi Friend, I wnat to use substring() function in my project. I have used it now for my work purpose but i am not satisfy with that. Actually i don't know how to use it when you don't know the length of the file name. Currently i know the file name so according to that i am putting substring function like ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>50. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2107270&tstart=114150'>Can i substring from the end ..?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>for example i have 12345 i want to insert "1" and then i get 123 This makes no sense whatsoever. Please make an effort to communicate your problem more clearely From yor "substring from the end" subject line and the example your provided, I'm going to go WAAAAAYYYYY out on a limb and wild-a$$-guess that you want to provide a number ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>51. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2109515&tstart=117525'>How to remove a substring from a String?</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>Hi, I have a string with a lot of content and I want to remove certain parts. I want to remove all occurrences of "http://.....". Each http-adress end with a space, I mean theres a space separating the adress from the rest of the content (both before and after). Any help much appreciated! </p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>52. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2109850&tstart=118065'>removing substring from string</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>hi i have an XML in String format. need to remove schema from it. such as everything between <isFavourite>...bla bla bla </isFavourite> and the tags too. dont wanna create an xml file for input output processing etc... need some method to work directly on the string. it is a huge xml string so how do i remove different sections from it...its ...</p></div></td></tr><tr><td><div class='articleProductElement'><h3 class='articleProductElementTitle'>53. <a href='https://forums.oracle.com/forums/thread.jspa?threadID=2110320&tstart=118860'>Substring Method</a><span class='articleProductElementHost'>    forums.oracle.com</span></h3><p class='articleProductElementParagraph'>As you can see from the code I want to use the variable Name as a string in the substring method. Can anyone tell me if this correct? Or can it be done? NP: I will be using a NamesTest.java to enter the text Joe so that notation = Joe and Name = notation. </p></div></td></tr></table></div></div><footer><p class='pull-right'><a href='http://www.java2s.com/'>java2s.com</a>  | © Demo Source and Support. All rights reserved.</p></footer></div></body></html>