Extracting Some Parts From A Given String?
Apr 9, 2015Suppose i have a string S="a.png,b.png,c.xlsx";
I need to extract only c.xlsx, how i will do these in java
Suppose i have a string S="a.png,b.png,c.xlsx";
I need to extract only c.xlsx, how i will do these in java
I was working on my personal project when I realized I needed to split a string and extract 2 elements of it. The way it works is the user enters 2 numbers separated by a comma like this: 4, 8. Then I want to put the first number into a veriable called x and the next number into a variable called y. How can I do this?
View Replies View RelatedOkay So I am creating an application but I'm not sure how to get certain parts of the string. I have read In a file as such:
*tp*|21394398437984|163600
*2*|AAA|1234567894561236|STOP|20140527|Success||Automated|DSPRN1234567
*2*|AAA|1234567894561237|STOP|20140527|Success||Automated|DPSRN1234568
*3*|2
I need to read the lines beggining with *2* so I done:
s = new Scanner(new BufferedReader(new FileReader("example.dat")));
while (s.hasNext()) {
String str1 = s.nextLine ();
if(str1.startsWith("*2*")){
System.out.print(str1);
}
}
So this will read the whole line I'm fine with that, Now my issue is I need to extract the 2nd line beggining with numbers the 4th with numbers the 5th with success and the 7th(DPSRN). I was thinking about using a String dilemeter with | how to extract them once i've used the dilemeter.
I want to extract a specific String from HTML, specifically, I want to extract a String from in between <...>
So far, I've got this
package main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class HTMLGrabber {
static String allOneString = "";
[code]....
The problem I have is when I change the last parameter in this line:
System.out.println("And the Keywords are:
" +allOneString.substring(allOneString.lastIndexOf("meta name="keywords" content=") + 30, allOneString.indexOf("Fictional History">")+17));
to
System.out.println("And the Keywords are:
" +allOneString.substring(allOneString.lastIndexOf("meta name="keywords" content=") + 30, allOneString.indexOf("">")));
i.e. the generic alternative, I get this error message:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -366
at java.lang.String.substring(Unknown Source)
at main.HTMLGrabber.main(HTMLGrabber.java:45)
Is there a better and simple way to extract a substring?
I am trying to do is extract numbers that are in word format in a long String, i.e. a song, and return each of their numerical values, in order to add them all up. So I'd like to calculate the sum of all of the numbers in the text. This has to work for any piece of text and for all numbers up to a trillion.
So I broke the string down into tokens and stored them in a String []. And I divided up the possible numbers in word format into:
LARGEST: thousand, million, billion, trillion
HUNDRED: hundred
TENS: twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
UNITS: one, two, three, four, five, six, seven, eight, nine
SPECIALS: ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen
I believe that these are the only words that it will need to recognize. I began reading the tokenized string from right to left and then when I came across a unit, special or tens as the first number I hit, I would then set it's numerical value and check if the word before was also a number and whether to add or multiply etc. i.e. First number hit is a two, if the number before is sixty, then I would just add it to sixty and check the word before that and so on.
However, when implementing it, it seems like an extremely long way around it. How I could implement this in a swifter manner? An example of it working would be:
"Nine Million rockets turned Three times and met Twenty Two Aliens", it would extract, Twenty Two as 2, then 20 = 22, then extract Three as 3, and then Nine Million as 1,000,000 x 9 = 9,000,000
9,000,000 + 22 + 3 = 9,000,025
so I have a Text File that looks like this:
JohnGibson9127OakDrCorvallisOR973305552812313156.78
RonWills1155IvyPlAtlanticGa373395552123145189.56
RitaJones1259ChaseAveLas VegasNV8712655544456712145.60
JasonKnight7154PineDrGresjam OR9738055581245453157.44
ClaraSwanson1944MainPlSpringfieldCA973395552123144212.99
it has first name tab, last name tab, so on I'm saying this because it kept changing format but they are Tabs betwwen each word.
I need to print it in the correct order, so I will need to break this down into objects such as FirstName, LastName,Adress ect. I don't know how to break it into pieces. here is my code thus far:
import java.io.*;
import java.util.Scanner;
public class Postal
{
[Code]....
in which while loop do I add these variables, and could i get a example of how to do one, like first name?
example input (#federer #great #game )->
output : [federer] [great][game], [federer, game],[federer,great], [game,great], [federer, game,great]
I am working on a card game and for lack of better terms, have royally screwed up my files. I do still have an executable jar that I would like to go back to if possible and try to redo what I messed up. What I was able to do was to use WinRAR and get ?encrypted? class files. Something that is obviously not editable. How can I go about converting these back to editable java files, if possible?
View Replies View RelatedI have a file that has the following text in it:
# Main configuration file for DEDServer
# Starting resource values
startingGold=1000000000
startingElixir=1000000000
[Code] ....
I am working on a time sheet program. I want to split punches into three parts.
Suppose an employee punch in at 8:45 am and punch out at 5:30 pm.
If the shift is 9:00 am to 4:30 , i want to split the above time period to period before shift, period in shift and period after shift.
In this case :-
8:45 am -9:00 am
9:00 am -4:30 pm
4:30 pm -5:30 pm
He had worked 15 minutes prior to his shift, 7.5 hours in his shift and 1 hour after his shift.
I want to do this to calculate regular hours and over time.
Is there any easy way to split this time interval ??
I have a couple more (2or3) and I believe I'll be ready to go 8-)This one is about an Army and a list of warriors... for example 1,2,3,4,5,6,7,9,10 .... and the user inputs points for two sequences, for example 1, 5 and 6,10 .... That means I have to take the array from the 1st element, up to the 5th one, and swap it with the elements from 6to10....
The nest list should be:
6 7 8 9 10 1 2 3 4 5
Things to keep in mind: The list will always have at least two warriors. The intervals will never interfere, and will at least contain ONE warrior..
It says: be careful when the intervals are next to each other, and when be careful when an interval starts with the first warrior, or finishes with the last warrior.
Divide an Array in two Parts in such a way so that sum will be equal while we add all the elements of array.
View Replies View RelatedI am trying to create a serversocket that send a binary in parts ie send 1024 bytes then wait for acknowledgement from the client before sending the next 1024. I am able to do it in udp but the client is tcp. This is my code so far
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class TestFtp {
[Code]....
I have not been able to send then receive acknowledgement before sending the next 1024 bytes.
I have these sample strings in a text file : goldfish, fish, dish, filter and i need to extract them out with letters : "is" and need to print them out in another text file. Currently I am able to read the contents of the file but I am not able to print the same it in the new file.
public class Demo {
public static void main(String[] args) {
String filename = "a.txt";
try {
[code]....
I've been working quite a bit with a login system the past couple of months and I now have a version that I would like to try "for real" by extracting it as a runnable .jar or .exe file. I've looked at a couple of guides that told me how to do this properly, but even after following every step precisely it didn't work.
One of the guides I tried: 3 Ways to Create an Executable File from Eclipse - wikiHow
Double clicking the file or selecting it and pressing enter does nothing, the computer loads for a second and then nothing happens. I don't receive any visible errors when extracting the program, either.
However, when running the file from the command prompt I do receive an odd error:
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:UsersUserName>java -jar Login.jar
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at LoginSystem.Data.updateData(Data.java:347)
at LoginSystem.Data.<init>(Data.java:309)
at LoginSystem.MainFrame.<init>(MainFrame.java:42)
at LoginSystem.MainFrame.main(MainFrame.java:457)
C:UsersUserName>
I must say I don't quite understand the error, it seems to be unable to load an image which is odd considering the program works fine without any errors at all in Eclipse.
code for extracting kerala state vehicle number plate from an image
View Replies View RelatedI have to implement a system where I have to do almost same processing on a jsp page. The slight differences on the present page is based on whether the current page came from page 1 or page 2. So how can I do this?
View Replies View Relatedjava code for adding one text file into the zipped file without extracting It is possible in java code ?
View Replies View RelatedLet's say hypothetically you're making a huge program and use a lot of imports (ex import java.util). If you only need a few specific things from java.util, will it use more memory importing java.util.* compared to only importing lets say java.util.Scanner, java.util.ArrayList, etc. Basically does importing a whole package use more (if any at all) memory than only importing specific package parts?
View Replies View RelatedHow can I write a method that takes a string with duplicates letters and returns the same string which does not contain duplicates. For example, if you pass it radar, it will return rad. Also i would like to know how can I Write a method that takes as parameters the secret word and the good guesses and returns a string that is the secretword but has dashes in the places where the player has not yet guessed that letter. For example, if the secret word is radar and the player has already guessed the good guesses letters r and d, the method will return r-d-r.
View Replies View RelatedI am currently trying to make a calculator in Java. I want to use the String split method to tokenize the string of characters inputted. I thought I was using the String split method wrongly, because I had surrounded the characters I wanted to delimit with square brackets. However, when I removed the square brackets, the code threw an exception when I pressed the equal button. The exception was a PatternSyntaxException exception. Am I using the String split method wrongly? And why is the exception thrown? Here is my code:
import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.List;
import static java.lang.Math.*;
public class CalculatorCopy {
public static void main(String[] args) {
[Code] .....
i am trying to write a class method which will take in a string and returns a string which is the reversed version of that string. it compiles fine but when i try to run it it states Main method not found in class StringReverse,please define the main method as public static void main(String[]args). I am new to java and cannot figure out
import javax.swing.JOptionPane;
public class StringReverse {
public String reverseString(String str){
JOptionPane.showInputDialog(null,"Please enter word");
char c = str.charAt(str.length()-1);
if(str.length() == 1) return Character.toString(c);
return c + reverseString(str.substring(0,str.length()-1));}}
I'm having trouble with the last few lines of the code. It's supposed to take a replacement string entered by the user and print out the new string. For some reason it's now allowing me to enter a replacement string
import java.util.Scanner;
public class Project02 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a long string: ");
String lString = keyboard.nextLine();
[Code] ....
Output:
Enter a long string: the quick brown fox jumped over the lazy dog
Enter a substring: jumped
Length of your string: 44
Length of your substring: 6
Starting position of your substring in string: 20
String before your substring: the quick brown fox
String after your substring: over the lazy dog
Enter a position between 0 and 43: 18
The character at position 18 is x
Enter a replacement string: Your new string is: the quick brown fox over the lazy dog <------ isn't taking user input
I have a method for a button so when a user inputs something it then will get the string value and check it against the string value within the properties file to see if it exists.
The properties file is called GitCommands.properties that contains -- > key = value <-- in it
I realised I have not used it correctly hence why I keep getting errors - I am lost on how to use it, I think perhaps that may be the issue here? I need to reference the file but I am doing it wrong? When I do use that piece of code I get null pointer exception too...
textFieldSearch.getText().equals(GitCommands.keys());
This is my button:
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FindSelectedKey();
[code] .....
I understand I am missing my piece of code where it states "//determine whether the string is equal to the property file key string" I understand the logic fine but not actually coding it.
I am trying to split a string based on length(example length 5) of the string. But I am having a issues with this substring(start, end) method. I get all substring which are of length 5. But if the last substring is less than 5 then I am not getting that last substring. But I need the last substring even if it is less than 5.
String s = "fjdjfdfjgffgjhfjghfjkhjhjh";
String spLine;
for(int i=0; i<s.length(); i=i+5){
spLine = s.substring(i, (5+i));
}
>
Code a Java method that accepts a String array and a String. The method should return true if the string can be found as an element of the array and false otherwise. Test your method by calling it from the main method which supplies its two parameters (no user input required). Use an array initialiser list to initialise the array you pass. Test thoroughly.
public class test {
public static void main(String[] args) {
Printhelloworld();
String[] verbs = {"go", "do", "some", "homework"};
printArrays(verbs);
[Code] .....