How can I re-organize String lines
Hello My String consists of random lines. Every line has an priority number. Example of a String:
Done id pri created finished description
000 1 2006-12-11 - job
x 001 2 2006-12-11 - do this
002 3 2006-12-11 - work
x 003 0 2006-12-11 - some
004 2 2006-12-11 - thing
005 1 2006-12-11 - reads
006 0 2006-12-11 - here
Every "token" is seperated by \t (done \t id \t ....\t 000 \t 1 \t 2006-12-12 \t...)
How can I organize the String and save it to another String so that pri-values are in a descending order:
Done id pri created finished description
002 3 2006-12-11 - work
x 001 2 2006-12-11 - do this
004 2 2006-12-11 - thing
000 1 2006-12-11 - job
005 1 2006-12-11 - reads
x 003 0 2006-12-11 - some
006 0 2006-12-11 - here
I'm trying but I don't know what I'm doing
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Comparator;
public class Start {
public static void main(String[] args) throws IOException {
sort();
public static void sort() throws IOException {
class Work implements Comparable {
String id;
int pri;
String d1;
String d2;
String job;
public Work(String id, int pri, String d1, String d2, String job){
this.id = id;
this.pri = pri;
this.d1 = d1;
this.d2 = d2;
this.job = job;
BufferedReader reader = new BufferedReader(new FileReader("Tehtava.txt"));
//BufferedWriter writer = new BufferedWriter(new FileWriter("Tempo.txt"));
String lookingFor3 = "-";
String line = null;
while ((line = reader.readLine()) != null) { //---------------z
String[]result = line.split("\t");
List tasks = new ArrayList();
if (result[4].equals(lookingFor) == true) {
tasks.add(new Work(line));
continue;
public int getpri() {
return pri; }
public int compareTo(Object o) {
Work otherWork = (Work) o;
return this.getpri().compareTo(otherWork.getpri()); }
Collections.sort(tasks); //-------------------x
System.out.print(tasks); //------------------x
//reader.close();
}I don't know what but Where and I'm getting errors like:
<identifier> expected
for lines ------------x
illegal start of type:
for line -------------z
Similar Messages
-
How can I input read a line from a file and output it into the screen?
How can I input read a line from a file and output it into the screen?
If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
Any help will be appreciate!
======START FILE default.html ========
<html>
<body>
<br><br>
<center>
<font size=4 face=arial color=#336699>
<b>Welcome to a DerekTran's Website!</b><br>
Underconstructions.... <br>
</font> </center>
<font size=3 face=arial color=black> <br>
Hello,<br>
<br>
I've been using the PWS to run the website on NT workstation 4.0. It was working
fine. <br>
The URL should be as below: <br>
http://127.0.0.1/index.htm or http://localhost/index.htm
<p>And suddently, it stops working, it can't find the connection. I tried to figure
out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
know what's going on? Please see the link for more.... I believe that I setup
everything correctly and the bugs still flying in the server.... <br>
Thank you for your help.</P>
</font>
<p><font size=3 face=arial color=black>PeerWebServer.doc
<br>
<p><font size=3 face=arial color=black>CannotFindServer.doc
<br>
<p><font size=3 face=arial color=black>HOSTS file is not found
<br>
<p><font size=3 face=arial color=black>LMHOSTS file
<br>
<p><font size=3 face=arial color=black>How to Setup PWS on NT
<BR>
<p><font size=3 face=arial color=black>Issdmin doc</BR>
Please be patient while the document is download....</font>
<font size=3 face=arial color=black><br>If you have any ideas please drop me a
few words at [email protected] </font><br>
<br>
<br>
</p>
<p><!--#include file="Hits.asp"--> </p>
</body>
</html>
========= END OF FILE ===============Hi!
This is a possible solution to your problem.
import java.io.*;
class AddressExtractor {
public static void main(String args[]) throws IOException{
//retrieve the commandline parameters
String fileName = "default.html";
if (args.length != 0) fileName =args[0];
else {
System.out.println("Usage : java AddressExtractor <htmlfile>");
System.exit(0);
BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
StreamTokenizer st = new StreamTokenizer(in);
st.lowerCaseMode(true);
st.wordChars('/','/'); //include '/' chars as part of token
st.wordChars(':',':'); //include ':' chars as part of token
st.quoteChar('\"'); //set the " quote char
int i;
while (st.ttype != StreamTokenizer.TT_EOF) {
i = st.nextToken();
if (st.ttype == StreamTokenizer.TT_WORD) {
if (st.sval.equals("href")) {
i = st.nextToken(); //the next token (assumed) is the '=' sign
i = st.nextToken(); //then after it is the href value.
getURL(st.sval); //retrieve address
in.close();
static void getURL(String s) {
//Check string if it has http:// and truncate if it does
if (s.indexOf("http://") > -1) {
s = s.substring(s.indexOf("http://") + 7, s.length());
//check if not mailto: do not print otherwise
if (s.indexOf("mailto:") != -1) return;
//printout anything after http:// and the next '/'
//if no '/' then print all
if (s.indexOf('/') > -1) {
System.out.println(s.substring(0, s.indexOf('/')));
} else System.out.println(s);
}Hope this helps. I used static methods instead of encapsulating everyting into a class. -
How can i extract data strings (temperature, pressure, relative humidity etc) using a Virtual interface through an RS-232 connection?
Try this. It is in LV 8.5.
Note the double % in the format string. This is so the % in the input string is treated as a percent rather than a code.
You may also have to work with the line feed characters in case they are different in the string coming in compared to how the string shows up in the web browser.
Message Edited by Ravens Fan on 02-12-2008 10:19 PM
Attachments:
Example_BD.png 4 KB
Untitled 11.vi 9 KB -
How can we get the selected line number from JTextArea ?
how can we get the selected line number from JTextArea ? and want to insert line/string given line number into JTextArea??? is it possible ?
Praitheesh wrote:
how can we get the selected line number from JTextArea ?
textArea.getLineOfOffset(textArea.getCaretPosition());
and want to insert line/string given line number into JTextArea??? is it possible ?
int lineToInsertAt = 5; // Whatever you want.
int offs = textArea.getLineStartOffset(lineToInsertAt);
textArea.insert("Text to insert", offs); -
How can i write a string into a specified pos of a file?
How can i write a string into a specified pos of a file without read all file into ram and write the whole file again?
for example:
the content of file is:
name=123
state=456
i want to modify the value of name with 789
(write to file without read all file into ram)
How can i do it? thank youtake this as an idea. it actually does what i decribed above. you sure need to make some modifications so it works for your special need. If you use it and add any valuable code to it or find any bugs, please let me know.
import java.io.*;
import java.util.*;
* Copyright (c) 2002 Frank Fischer <[email protected]>
* All rights reserved. See the LICENSE for usage conditions
* ObjectProperties.java
* version 1.0, 2002-09-12
* author Frank Fischer <[email protected]>
public class ObjectProperties
// the seperator between the param-name and the value in the prooperties file
private static final String separator = "=";
// the vector where we put the arrays in
private Vector PropertiesSet;
// the array where we put the param/value pairs in
private String propvaluepair[][];
// the name of the object the properties file is for
public String ObjectPropertiesFileName;
// the path to the object'a properties file
public String ObjectPropertiesDir;
// reference to the properties file
public File PropertiesFile;
// sign for linebreak - depends on platforms
public static final String newline = System.getProperty("line.separator");
public ObjectProperties(String ObjectPropertiesFileName, String ObjectPropertiesDir, ObjectPropertiesManager ObjectPropertiesManager)
// System.out.println("Properties Objekt wird erzeugt: "+ObjectPropertiesFileName);
this.ObjectPropertiesFileName = ObjectPropertiesFileName;
this.ObjectPropertiesDir = ObjectPropertiesDir;
// reference to the properties file
PropertiesFile = new File(ObjectPropertiesDir+ObjectPropertiesFileName);
// vector to put the param/value pair-array in
PropertiesSet = new Vector();
// System.out.println("Properties File Backup wird erzeugt: "+name);
backup();
// System.out.println("Properties File wird eingelesen: "+PropertiesFile);
try
//opening stream to file for read operations
FileInputStream FileInput = new FileInputStream(PropertiesFile);
DataInputStream DataInput = new DataInputStream(FileInput);
String line = "";
//reading line after line of the properties file
while ((line = DataInput.readLine()) != null)
//just making sure there are no whitespaces at the beginng or end of the line
line = cutSpaces(line);
if (line.length() > 0)
//$ indicates a param-name
if (line.startsWith("$"))
// array to store a param/value pair in
propvaluepair = new String[1][2];
//get the param-name
String parameter = line.substring(1, line.indexOf(separator)-1);
//just making sure there are no whitespaces at the beginng or end of the variable
parameter = cutSpaces(parameter);
//get the value
String value = line.substring(line.indexOf(separator)+1, line.length());
//just making sure there are no whitespaces at the beginng or end of the variable
value = cutSpaces(value);
//put the param-name and the value into an array
propvaluepair[0][0] = parameter;
propvaluepair[0][1] = value;
// System.out.println("["+ObjectPropertiesFileName+"] key/value gefunden:"+parameter+";"+value);
//and finaly put the array into the vector
PropertiesSet.addElement(propvaluepair);
// error handlig
catch (IOException e)
System.out.println("ERROR occured while reading property file for: "+ObjectPropertiesFileName);
System.out.println("ERROR CODE: "+e);
// System.out.println("in ObjectProperties");
// function to be called to get the value of a specific paramater 'param'
// if the specific paramater is not found '-1' is returned to indicate that case
public String getParam(String param)
// the return value indicating that the param we are searching for is not found
String v = "-1";
// looking up the whole Vector
for (int i=0; i<PropertiesSet.size(); i++)
//the String i want to read the values in again
String s[][] = new String[1][2];
// trying to get out the array from the vector again
s = (String[][]) PropertiesSet.elementAt(i);
// comparing the param-name we're looking for with the param-name in the array we took out the vector at position i
if (s[0][0].equals(param) == true)
//if the param-names are the same, we look up the value and write it in the return variable
v = s[0][1];
// making sure the for loop ends
i = PropertiesSet.size();
// giving the value back to the calling procedure
return v;
// function to be called to set the value of a specific paramater 'param'
public void setParam(String param, String value)
// looking up the whole Vector for the specific param if existing or not
for (int i=0; i<PropertiesSet.size(); i++)
//the String i want to read the values in again
String s[][] = (String[][]) PropertiesSet.elementAt(i);
// comparing the param-name we're looking for with the param-name in the array we took out the vector at position i
if (s[0][0].equals(param) == true)
//if the param-names are the same, we remove the param/value pair so we can add the new pair later in
PropertiesSet.removeElementAt(i);
// making sure the for loop ends
i = PropertiesSet.size();
// if we land here, there is no such param in the Vector, either there was none form the beginng
// or there was one but we took it out.
// create a string array to place the param/value pair in
String n[][] = new String[1][2];
// add the param/value par
n[0][0] = param;
n[0][1] = value;
// add the string array to the vector
PropertiesSet.addElement(n);
// function to save all data in the Vector to the properties file
// must be done because properties might be changing while runtime
// and changes are just hold in memory while runntime
public void store()
backup();
String outtofile = "# file created/modified on "+createDate("-")+" "+createTime("-")+newline+newline;
try
//opening stream to file for write operations
FileOutputStream PropertiesFileOuput = new FileOutputStream(PropertiesFile);
DataOutputStream PropertiesDataOutput = new DataOutputStream(PropertiesFileOuput);
// looping over all param/value pairs in the vector
for (int i=0; i<PropertiesSet.size(); i++)
//the String i want to read the values in
String s[][] = new String[1][2];
// trying to get out the array from the vector again
s = (String[][]) PropertiesSet.elementAt(i);
String param = "$"+s[0][0];
String value = s[0][1];
outtofile += param+" = "+value+newline;
outtofile += newline+"#end of file"+newline;
try
PropertiesDataOutput.writeBytes(outtofile);
catch (IOException e)
System.out.println("ERROR while writing to Properties File: "+e);
catch (IOException e)
System.out.println("ERROR occured while writing to the property file for: "+ObjectPropertiesFileName);
System.out.println("ERROR CODE: "+e);
// sometimes before overwritting old value it's a good idea to backup old values
public void backup()
try
// reference to the original properties file
File OriginalFile = new File(ObjectPropertiesDir+ObjectPropertiesFileName);
File BackupFile = new File(ObjectPropertiesDir+"/backup/"+ObjectPropertiesFileName+".backup");
//opening stream to original file for read operations
FileInputStream OriginalFileInput = new FileInputStream(OriginalFile);
DataInputStream OriginalFileDataInput = new DataInputStream(OriginalFileInput);
//opening stream to backup file for write operations
FileOutputStream BackupFileOutput = new FileOutputStream(BackupFile);
DataOutputStream BackupFileDataOutput = new DataOutputStream(BackupFileOutput);
// String content = "";
String line = "";
// do till end of file
while ((line = OriginalFileDataInput.readLine()) != null)
BackupFileDataOutput.writeBytes(line+newline);
// error handlig
catch (IOException e)
System.out.println("ERROR occured while back up for property file: "+ObjectPropertiesFileName);
System.out.println("ERROR CODE: "+e);
System.out.println("this is a serious error - the server must be stopped");
private String cutSpaces(String s)
while (s.startsWith(" "))
s = s.substring(1, s.length());
while (s.endsWith(" "))
s = s.substring(0, s.length()-1);
return s;
public String createDate(String seperator)
Date datum = new Date();
String currentdatum = new String();
int year, month, date;
year = datum.getYear()+1900;
month = datum.getMonth()+1;
date = datum.getDate();
currentdatum = ""+year+seperator;
if (month < 10)
currentdatum = currentdatum+"0"+month+seperator;
else
currentdatum = currentdatum+month+seperator;
if (date < 10)
currentdatum = currentdatum+"0"+date;
else
currentdatum = currentdatum+date;
return currentdatum;
public String createTime(String seperator)
Date time = new Date();
String currenttime = new String();
int hours, minutes, seconds;
hours = time.getHours();
minutes = time.getMinutes();
seconds = time.getSeconds();
if (hours < 10)
currenttime = currenttime+"0"+hours+seperator;
else
currenttime = currenttime+hours+seperator;
if (minutes < 10)
currenttime = currenttime+"0"+minutes+seperator;
else
currenttime = currenttime+minutes+seperator;
if (seconds < 10)
currenttime = currenttime+"0"+seconds;
else
currenttime = currenttime+seconds;
return currenttime; -
How can i go to new line when iam writing data to a file by using write to spraedsheet file.vi every time.i mean i would like to go to newline everytime.
Take a look at the attached code. I am writing a 2-D array to the file using the default method so it looks like
1 2 3
4 5 6
7 8 9
in the file.
I then use the Line Feed Constant as a delimiter, and you can see it then looks like
1
2
3
4
5
6
7
8
9
The line feed and carriage return constant is on the String Pallette.
Attachments:
WriteSpreadSheet.vi 19 KB -
I recently bought an iPod touch 5th generation, I had a few CD albums here that I wanted to put into my new iPod, just like my old one. But with my old one I put them all in and it organized them all as the same artist (which they are), so under artists I just had to click on their name, then pick the album. In the 5th gen one, it puts the songs in my iPod, but I can't find the actual album under "Artists". I put 2 albums by this artist, but it only shows one, and the other is nowhere to be found, but it's still in my iPod, just as individual songs in the songs section. I don't think this'll be the only time I'm running into this problem on the 5th gen, I had trouble organizing some other songs. How can I better organize these albums, show them all under the same artist? I tried to re-write the artist name to be exactly the same, but that doesn't do anything.
I would either say that the iOS is correpted due to a software glitch or y have have a hardware problem like bad memory locations that are corrupting the iOS.
- Restore from backup via iTunes. This will install a fresh copy of the iOS. See:
iOS: How to back up
- Restore to factory settings/new iOS device. This will elimate corruptin in the backup causing the problem.
If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
Apple Retail Store - Genius Bar -
How can I send multiple string commands into a VISA write?
Hi Fellow LabVIEW users
I am very new to LabVIEW (2.5 months) so please forgive me if my lingo is not up to par.
How can I send multiple string commands to a VISA write. For example each string command looks like this
1) 3A00 0000 0000 FFFF FFFF FFFF 0000 0000 FF00 0000 0000 0000 0000 0033 (Scenario 1)
2) 3A01 0000 0000 FFFF FFFF FFFF 0000 0000 FF00 0000 0000 0000 0000 0034 (Scenario 2)
3) 3A01 0000 0000 33FF FFFF FFFF 0000 0000 FF00 0000 0000 0000 0000 0067 (Scenario 3).
and so on and so forth. And there are a number of scenarios.
Each String scenario will give a different string output which will be interpreted differently in the front panel.
Right now I have to manually change the string commands on the front panel to give me the desired output. How can I do this without manually changing the commands i.e. hard coding each scenario into the block diagram?
Thanks, any feedback will help.
mhaquePlease stick to your original post.
-
How can I add a new line item for production order?
HI all,
How can I add a new line item for production order through BAPI/FM? Thanks in advance.Hi Mil,
Unfortunetly SAP is not in front of me.
But if possible go to BAPI transaction , check for any production order's bapi for CHANGE purpose. Where you will be able to add your new line.
Reward if useful! -
How can I print the "number lines" with the code in Visual Studio?
How can I print the "number lines" with the code in Visual Studio?
Hi BillionaireMan,
What about your issue now?
If you have resolved it, you can share the solution here, which will be beneficial for other members with the same issue.
If you did not, please tell us more information,we will try my best to help you.
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
So, how can I add the red line below all those words, which are not technically correct.
I have tried everything, but nothing works. Red line should come there automatically, but I can't find nothing from settings to do this. Can you guys help me?There isn't any finnish spellcheck in Pages
Inspector palette = Asetukset
I am trying to find out where to get a finnish dictionary that can work in Pages. I am not sure but try this
http://www.jkwchui.com/2010/03/spellchecking-latex-in-macosx/ -
How can I search the last line in an internal table?
How can I search the last line in an internal table?
With a describe?? If it is , how can I do that?
Thanks!!Hi shilpa,
it seems to be you are NEW to SDN. welcome. if you want to get solutions to your Questions, you have to post a NEW thread.dont use the existing thread to post your question.
any way i am giving you the solution for your question
LOOP AT ITAB WHERE F1 = <SOME VALUE>
F2 = <SOME VALUE>.
ENDLOOP.
IF SY-SUBRC = 0.
ITAB WILL HAVE THE LAST RECORD which satisfying the given criteria in WHERE clause of LOOP.
write itab <--this ITAB will have the last record.
ENDIF.
regards,
Srikanth.
Message was edited by: Srikanth Kidambi -
How can I use srvctl command line for change "Failover type" and "F method"
Hi all,
I am using Oracle One Node (11.2.0.3), and I have a service:
/u01/11.2.0/grid/bin/srvctl config service -d orcl
Service name: orcldb
Service is enabled
Server pool: orcl
Cardinality: 1
Disconnect: false
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Failover type: NONE
Failover method: NONE
TAF failover retries: 0
TAF failover delay: 0
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: BASIC
Edition:
Preferred instances: orcl_1
Available instances:
I would like to change "Failover type" and "Failover method" to:
Failover type: SELECT
Failover method: BASIC
How can I do that? Is there any graphical tool for it? Or, How can I use srvctl command line for change it?
Thanks in advance.
Leonardo.user10674190 wrote:
Hi all,
I am using Oracle One Node (11.2.0.3), and I have a service:
/u01/11.2.0/grid/bin/srvctl config service -d orcl
Service name: orcldb
Service is enabled
Server pool: orcl
Cardinality: 1
Disconnect: false
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Failover type: NONE
Failover method: NONE
TAF failover retries: 0
TAF failover delay: 0
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: BASIC
Edition:
Preferred instances: orcl_1
Available instances:
I would like to change "Failover type" and "Failover method" to:
Failover type: SELECT
Failover method: BASIC
How can I do that? Is there any graphical tool for it? Or, How can I use srvctl command line for change it?
Thanks in advance.
Leonardo.srvctl modify service -d database_name -s orcldb -q TRUE -m BASIC -P BASIC -e SELECT -z 180 -w 5 -j LONG
Also see
11gR2(11.2) RAC TAF Configuration for Admin and Policy Managed Databases [ID 1312749.1] -
How can i make it auto line alignment in ScriptUI?
I want that form recognize new line character. (like '\n')
So I programmed like this. But it's not working.
var win =new Window ("dialog", "test");
win.orientation = "column";
var form1 = win.add ("edittext", undefined, "");
form1.onChanging = function(){
if(form1.text.search("\n") == true){
form2.active = true;
var form2 = win.add ("edittext", undefined, "");
var form3 = win.add ("edittext", undefined, "");
win.show();
How can i make it auto line alignment in ScriptUI?
Is it possible?Your answer is not exactely I want.
But I got hint from your answer.
All I want is "How I can split multilined text into dozen edittext field?"
So I can make this from your sourcecode.
Your answer is so helpful.
Thank you.
var win = new Window ("dialog", "test");
win.orientation = "column";
var charLen=30;
var copytext = [];
var form0 = win.add ("edittext", [0, 0, 150, 200], "", {multiline:true});
form0.height = 100;
var form1 = win.add ("edittext", undefined, "",{readonly:true});
form1.characters = charLen;
var form2 = win.add ("edittext", undefined, "",{readonly:true});
form2.characters = charLen;
var form3 = win.add ("edittext", undefined, "",{readonly:true});
form3.characters = charLen;
form1.active = true;
form0.onChanging = function(){
form1.text = form0.text.split('\n')[0]
form2.text = form0.text.split('\n')[1]
form3.text = form0.text.split('\n')[2]
win.show(); -
How can I change perspective (converging lines) in iPhoto?
How can I change perspective (converging lines) in iPhoto?
iPhoto Menu -> preferences -> Accounts
Regards
TD
Maybe you are looking for
-
Runtime Error when accessing KM Content
Hi Everyone, I am getting Runtime Error when accessing KM Content through Content Administration/KM Content. See the below error information. Runtime Error An exception occured while processing the request. Additional information: String index out of
-
Preferences error - could not load displays preference pane
My screen resolution changed during game play. Now that the game is off, I cant change it back. This is what the error message says "Preferences Error - Could not load Displays preference pane."
-
Important question to Steve about passivateState() method
<br> <font size="2">Hello Steve, <br><br>I want to store information about application user in oracle.jbo.Session hastable. It's stored as pair KEY --> VALUE. To be sure that these informations will be accessible after passivation AM I have overreade
-
How to make two create.js files work on same page?
Can someone please help me? I have two flash banners that are different and are placed in separate divs on my webpage in dreamweaver. All was fine while they were .swt files except they were not visible on cellphones and tablets. So I converted them
-
Mass maintenance for router determination config
In transaction OVLM (Maintain Route Determination), is there a simple way to mass load a single new Shipping condition with generic and multiple transportation groups to all combinations of country of departure/transportation zone and country of dest