Extracting Numbers In Word Format From A String Of Text
Aug 7, 2014
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:
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
I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.
public static void main(String[] args) { int intBegin = 0; int intEnd = 1; int length; String charact; StringBuilder numbuilder = new StringBuilder();
[Code] .....
The error message I'm getting is:
run: The length is 13 intBegin is at 0 intEnd is at 1 index is at 0 Charcter ( was not inserted
Consider in a Document if a String " Hello" is Encoded and stored as "XYZAB"
I want to search the text on document for a word "Hello" and Replace the word with "HelloWorld"
The Program will encrypt the word "Hello" and Search the file then return the encrypted code as "XYZAB" Found
Now i have to replace the word "Hello" with "HelloWorld" in encrypted form so that the Letter "XYZABEFGHI" is replace in the place of Hello where "World" is encoded as "EFGHI"
Now the Problem is If there is more number of occurrence of the word "Helloworld" exist in the file... How can i Replace only one particular occurrence What can be done to select the particular occurrence.
I have attached my java program for Encryption along with this mail for your ease of use.
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 {
The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",
Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . How I can call that isSimilar method and read in that text file and change that word into that?
import java.util.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class WahidMuhammadA3Q2{ String fileName = "AutoCorrectMe.txt"; public static void main (String [] args){
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 need a Java algorithm that converts a string of numbers into text. It is related to how a phone keypad works where pressing 2 three times creates the letter "c" or pressing 4 one time creates the letter "g". For example a string of numbers "44335557075557777" should decode where 0 equates to a space.
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() { System.out.println("There are " + findUniqueWords(root, 0) + " unique words."); } private int findUniqueWords(Node subTree, int uniqueCount) { // Base Case: At the end of the branch if(subTree == null){ return uniqueCount;
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?
Write a program that reads number between 1,000 and 999,999 from the user and prints it without a comma separating the thousands. Read the input as string. Find the length of the string and use the substring to break it into two pieces. Do not include the comma. You can then concatenate using the + symbol to reassemble without the comma. For example if the number is 123,456. First would equal 123 and second would equal 456. noCommaNumber - 123456.
I do not think it is required to only allow numbers in that range in the code. My question is how to get the first half of the number before the comma in a string to make the last line work. What I think is not doing what I need is the line String first = numberIn.substring(numberIn.indexOf(",", 0)); This is just the last thing I tried.Getting the second half is done using IndexLastOf method in the substring class javaforumquest.jpg
I need a java code to search a certain word from the text file. the word that i want to search is in other text file. and finally the output will print the result in the new text file. for the example the text file name data.txt and the word list in the wordlist.txt and the output will print filter.txt.
This part of the code searches for every word in the text file and saves it to an ArrayList. It searches for the word if its valid of not.How can I offer a list of similar words when the word that the user inputs is not in the dictionary. Also I want it to prompt the user to accept the word or enter a replacement that gets saved in the dictionary.
I'm scanning my text and I want to add them into array list, but it is not easy. I want each word store from arrayList of a to z which is arrayList size is 26. Example:
arrayList a store string array of: an, and, apple, ...
arrayList b store string array of: be, become, became..... . arrayList z store string array of: zero, zone...
In my class, I create:
private static ArrayList<String[]> words = new ArrayList<String[]>(26); // to store all words
In main, I do while loop to get each words and store in words array,
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class BinaryTree {
Why is it simple for a word processing software (one that reads number of words, words greater that x characters etc) to deal with text file(.txt) and not with a doc file (.doc) file?? Is there any special requirements or what are the points taken into consideration while developing the software for a .doc file?
The program below compiles and functions correctly for the most part. It is supposed to be a simple GUI Text Editor with Edit and Format functions. The content pane is supposed to be a scroll pane, however no matter how much I type into the editor, the scroll bar does not appear. Also, the none of the functions under the "Edit" menu work.
So the exercise I'm working on says to have the user enter their name and the program will output their name with the last name in all caps. i made it work BUT the only way i could figure it out was to ask for the first and last names separately creating two strings rather than one.
Of course I want to make it work how it's supposed to (with one string) so that I'm learning. I'm just having trouble conceptualizing how exactly (with varying lengths of names) to tell the program to only capitalize the second word... at first I thought create a substring beginning with the first letter of the last name and ending with the last...but again, therein lies the issue of varying name lengths.
is there a way to create a substring that beginIndex's at the first "space"? then i could just leave the endIndex parameter empty and it would take the whole word into a new string. and from there utilize toUpperCase to the new string?
Here's my code asking for the first and last names separately.
import java.util.Scanner; class nameEcho { public static void main ( String [] args ) { Scanner scan = new Scanner( System.in ); String first; String last;
I'm very new to Java, and I'm writing a code to search a string to see how many times the word "dog" is found in it. I'm not sure if this is error-free or the most efficient, but I'd like to keep it simple.
public void run() {
String input = new String("The Dogman was no ordinary dog, nor man, but rather a peculiar dog-like man who barked like a dog, and panted like a dog, he even ate like a dog. He owned a dog named Doglips, and interestingly enough, his favorite food was hotdogs.");
println(input); int index = -1; int count = 0; print("Counting dogs:"); inputarray = input.split(" ");
What I need to do is ask the user to input some text and then turn it into pig latin. I am confused on how to select each word from the string to determine if it ends in a way or ay. I am to assume that the letters are all lowercase and the text ends with a period.
import java.util.Scanner; public class Trial { public static void main(String [ ] args) { Scanner input = new Scanner(System.in);
I have a form with primefaces input text(p:inputText).Many of the input text values are of the type currency in dollars.When i try to use ,it mandates the user to include $ symbol prepended to the value.Is there any way using which on blur of the field the dollar symbol is prepended and the number gets formatted with proper commas.
Alright, so let's say I have this string. I want to make it so that the string for this variable has to follow a certain format.
For example, "AAA-B", where the A's are a digit 0-9, the - is always in the same spot, and B is a letter but only from A-M. All of this for a single instance variable.
Is this possible? How could I go about doing this.