How can I convert a tab to a String
Hello,
I want to read a file, and check if in some place from the text there is a tab there, in case there exist one, repmplace for <tab8> or something like that.
I have the following.
import java.io.*;
import java.util.*;
public class Expander {
// other declarations ...
public static void expand(String[] args) {
// BufferedWriter br = new BufferedReader();
try{
if(args[0].equals("-v")){
System.out.println("Expander Version 1.0\nCopyright (C)");
if(args[0].equals("-h")){
System.out.println("");
System.out.println("Usage: java Expander [OPTION] ... [FILE] ...");
System.out.println("Convert tabs in each FILE to spaces, writing to standard output.");
System.out.println("Without FILE or with FILE = -, read from standard input.");
System.out.println("");
System.out.println("-i do not convert TABs after non-whitespace.");
System.out.println("-i=N have tabs (positive) N spaces apart, not the default 8.");
System.out.println("-h display this help message and exit.");
System.out.println("-v display version information and exit.");
if(args[0].equals("-i")){
BufferedReader in = new BufferedReader(new FileReader(args[1]));
String tempLine;
while((tempLine = in.readLine()) != null){
String temp = check(tempLine);
System.out.println(temp);
writeNew(temp,"1"+args[1]);
else
System.err.println("Command not Accepted, please check -h for more help");
catch(IOException e){System.out.println(e);}
catch(NoClassDefFoundError i){System.out.println(i);System.exit(0);}
}// closes readLoadData
public static String check(String line){
if ( line.equals("\t") )
return "<TAB8>";
else
return line;
public static void writeNew(String line, String args){
String name = args+".txt";
try
BufferedWriter out = new BufferedWriter(new FileWriter(name, true));
PrintWriter fw = new PrintWriter(out);
fw.print(line);
out.close();
catch(IOException e)
{ System.out.println(e);}
public static void main(String[] args) {
Expander.expand(args);
}any ideas?
Tahnks =)
Hi,
I guess the best way is to use regular expressions (must use SDK 1.4.1 or higher):
Add the line:
import java.util.regex.*;
and use one of the methods:
//Regex method to replace all \\t by <tab>
public String replaceTabs1(String line, String tab) {
Matcher matcher = Pattern.compile("\t").matcher(line);
tab = matcher.replaceAll("<tab>");
return line;
//Regex method to replace \\t by <tab> one by one
public String replaceTabs2(String line) {
Matcher matcher = Pattern.compile("\t").matcher(line);
while(matcher.find()){
line = matcher.replaceFirst("<tab>");
return line;
Or, use more general method to find and replace any string by any other string in your file
public String replaceText(String source, String find, String replace) {
Matcher matcher = Pattern.compile(find).matcher(source);
source = matcher.replaceAll(replace);
return source;
Hope it will work,
VM
Similar Messages
-
How can I convert an int to a string?
Hi
How can I convert an int to a string?
/ad87geaoHere is some the code:
public class GUI
extends Applet {
public GUI() {
lastValue = 5;
String temp = Integer.toString(lastValue);
System.out.println(temp);
showText(temp);
private void showText(final String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
tArea2.setText(text + "\n");
} -
How can I convert an ArrayList to a String[]
Hi,
How can I convert an ArrayList (only with strings) to a String[] ?
I've tried this :
public static String listToString(List l) {
StringBuffer sb = new StringBuffer();
Iterator iter = l.iterator();
while (iter.hasNext()) {
sb.append(iter.next().toString());
if (iter.hasNext()) {
sb.append(',');
return sb.toString();
But what I get is an array of xxxxx@435634 (for example).
Thanks a lot !Strings are Objects but not all Objects are Strings and at least one of the elements in your List is not a String.
-
How can i convert some caracteres of a String in bold characteres?? hELPME
How can i convert some caracteres of a String in bold caracteres?? hELPME
I have a JList and a DefaultListModel of Strings. So, i have many key words like "proccess", "if", "fi" that i want these characteres in bold.How i can use HTML in java to change a String to bold?
example
String str = "channel ";
str = <b>str</b>;
like this? syntax error =/ -
How can i convert JMS TextMessage into a String
Please tell me,How can i convert A JMS TextMessage into a String
http://java.sun.com/javaee/5/docs/api/javax/jms/TextMessage.html#getText()
-
How can I convert/read out from a string Hex (8-bit), the bit 0 length 1
How can I convert/read out from Hex (8-bit), the bit 0 length 1 (string subset!!??) and convert it to decimal.
With respect to one complement and two complement ?Just like Jeff, purely guessing here.
It almost sounds like you just need to Read from Binary File?
AND the 8-bit number with 1?
Need more details. What exactly do you have to start with? What exactly are you trying to get out of it? Examples help.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How can I convert a Waveform to a String-For​mat?
Hello,
I write with "SQL-Execute.vi" datas to an Access-file. The "SQL-Execute.vi" needs a statement in String Format. And that is my problem. My source-datas (that I want to save to Access) are Waveforms. How can I convert the Waveform datas to a String Format?
Thanks for help!Wire the waveform to the Get waveform componants function...from that you get t0, delta t and the sample values. Now you can generate whatever string you want based on that information...
You could e.g. wire the Y array to a for-loop in which you calculate the time of each sample by taking t0 and adding delta t multiplied with the array index, then you could convert the Y value and the time to strings using the seconds to time string and number to fractional string functions...etc etc...
MTO -
How can I convert date infomation to a string just includes the date not th
I just want the date like Thu 08, july 2004 but not the exact time.
how can I do that.The prior code produces a date formatted as Jul 7, 2004
To get Wed 07, July 2004, try this minor modification:
import java.text.DateFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
DateFormat format = new SimpleDateFormat("EEE dd, MMMM yyyy");
Date mydate = new Date();
String str = format.format(mydate);
System.out.println(str); -
HOW can I convert int value char TO String
I am trying to study Java by books, but sometimes it is quite difficult to find answers even to simple questions...
I am writing a program that analyzes a Chinese text in Unicode. What I get from the text is CHAR int value (in decimals), and now I need to find them in another text file (with RegEx). But I can't find a way how to convert an INT value of a char into a String.
Could you help me?
Thank you in advance.You are confusing matters a bit. A char is a char is a char, no matter
how you represent it. Have a look at this:char a= 'A';
char b= 65;Both a and b have the same value. The representation of that value
can be 'A' or 65 or even (char)('B'-1), because the decimal representation
of 'B' is 66. Note the funny construct (char)(...). This construct casts
the value ... back to the char type. Java performs all non-fraction
arithmetic using four byte integers. The cast transforms it back to
a two byte char type.
Strings are just concatenations of zero or more chars. the charAt(i)
method returns you the i-th char in a string. Have a look:String s= "AB";
char a= 'A';
char b= (char)(a+1);
if (a == s.charAt(0)) System.out.println("yep");
if (b == s.charAt(1)) System.out.println("yep");This piece of code prints "yep" two times. If you want to compare two
Strings instead, you have to do this:String s= "AB";
char a= 'A';
char b= 'B';
String t= ""+a+b;
if (s.equals(t)) System.out.println("yep");Note the 'equals' method instead of the '==' operator. Also note that
string t was constructed using those two chars. The above was a
shorthand of something like this:StringBuffer sb= new StringBuffer("");
sb.append(a);
sb.append(b);
String t= sb.toString();This is all handled by the compiler, for now, you can simply use the '+'
operator if you want to append a char to a string. Note that it is not
very efficient, but it'll do for now.
Does this get your started?
kind regards,
Jos -
How can i convert if the date in string format
String lFstr = (String) pReq.getParameter("FND");
String lTstr = (String) pReq.getParameter("TND");
String lLstr = (String) pReq.getParameter("LWD");
System.out.println(lFstr + " " + lTstr + " " + lLstr);
//DateFormat ds = DateFormat.getDateInstance();
DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
Date lFdate = null;
Date lTdate = null;
Date lLdate = null;
try {
lFdate = dateFormatter.parse(lFstr);
lTdate = dateFormatter.parse(lTstr);
lLdate = dateFormatter.parse(lLstr);
} catch (Exception e) {
System.out.println(lFdate+" "+lTdate+" "+lLdate);
i am getting the values from request parameters at that time it is giving values.
after convertion of string to date it is giving the null value what is wrong in this codeIt might have thrown an exception. Try printing the stack trace in the catch block.
-
How can I convert an entire excel workbook to pdf?
How can I convert an entire excel workbook to pdf? I have the box in the preferences for converting excel files marked to convert the entire workbook. I am using Abobe Acrobat 11 Statndard. This previously worked fine when I was using Adboe Acrobat 10 Statndard. Now in order to convert the entire workbook I have to open the excel file, Highlight all the workbook tabs and then save the file. Any ideas?
In Acrobat click Edit | Preferences | Convert to PDF: select Microsoft Office Excel, then click on Edit Settings. Make sure that 'Convert entire Excel workbook' is checked.
-
How can i convert the HTML information in XML form to a PDF?
Hi does any body know how can i convert the content of an HTML field in a XML Form in a regular text to include in a PDF in a Java program?
Hi ,
On the tool bar you have an option "Browser" which is next to "HTML Editor" .
You know that for using these elements wo have to map them with Data Schema.
Step by step
1. In data Model Under Data Schema Add a child and name it Read_More.
2. In the left hand corner ,click on tab Type and from the drop down select "rid"
3.Click on the "Browser" from the toolbar (as told earlier) and drag and drop it on the form.
4. Drag the Data schema which u have made(Read_more) and drop it on the browser on form. On right hand side u will se the mapping done.
5.Click on the "Browser" which is there in the form and on the right hand side of the form u will see the property window.
6.In property window change the value of action property to "Item Entry point"
7. Repeat step 3 and 4 in Render and show form but using "label" nad not browser.
Do not forget to add Save button in Edit Form.
This will solve your problem.
PS:Rewards Point Please.
Regards,
Naveen Gupta -
How can I convert MP3 file to AIFF to use in FCP?
Hi guys,
How can I convert an MP3 file to AIFF file to use it in Final Cut Pro?
Anyone please,
Thanks in advance,
Zia#5 Imported music from CD or iTunes
Shane's Stock Answer #5:
To get music into FCP, it needs to be an AIFF file at 48khz, 16 bit stereo. So if you want a song from a CD, you go into the iTunes Preferences and set this up under the IMPORTING tab:
File > preferences > importing > import using - AIFF encoder > Setting - Custom
Sample Rate - 48.000 kHz
Sample size - 16 bit
Channels - Stereo
If you have an mp3 that you want to use, then you can convert it thru iTunes as well.
If the piece of music you want to use is something you purchased thru iTunes, I'm afraid I can't help you there. There are copywrite issues that prevent files from being converted into the format that FCP can recognize.
Shane
"There's no need to fear, UNDERDOG is here!" -
how can i convert my song into .mr4 for making it my ringtone, just renaming it is not working?
Here's how:
If you are using Windows, make sure you are able to view the file extension.
http://support.microsoft.com/kb/865219
1. Select a title (.mp3 or .m4a) in your iTunes Music Library
2. Do File > Get Info on selected title (Windows do Edit > Get Info)
3. In the dialog choose Options tab
4. Set Start Time and End Time (no more than 35 secs otherwise won't work)
5. Close dialog.
6. Now control click the title (right click) and choose Create AAC Version
Note: If you don't have Create AAC version, switch in menu File > Preferences...(Windows do Edit > Preferences...) > General > Import Settings... > Import Using: AAC Encoder.
7. When it is done, drag the newly create title to the desktop.
8. Delete the newly create title in iTunes. <-- This step is important
9. Rename the title on your desktop from ringtone.m4a to ringtone.m4r
10. Drag and drop it into iTunes
Now you have a ringtone.
Make sure it is selected in iTunes > Tones for syncing with your new iPhone. -
How can I convert an InputStream to a FileInputStream ???
How can I convert an InputStream to a FileInputStream ???
Thanks for you reply, however, I am still stuck.
I am trying to convert my application (which runs smoothly) to a signed applet. The following is the original (application) code:
private void loadConfig() {
String fileName = "resources/groupconfig";
File name = new File(fileName);
if(name.isFile()) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
pAndGConfig = (PAGroupsConfig)in.readObject();
in.close();
return;
} catch(ClassNotFoundException e) {
System.err.println("++ERROR: "+e);
} catch(IOException e) {
System.err.println("++ERROR: "+e);
System.out.println("Can't find file: " + fileName);
Because all code and resources now reside in a Jar file (for the signed applet), I must use the following line to access the resources:
InputStream is = this.getClass().getResourceAsStream(fileName);
I then need to convert the 'InputStream' to 'ObjectInputStream' or 'FileInputStream' so that I can work with it.
I would be very grateful if you could help shed some light on the matter - Cobram
Maybe you are looking for
-
Disconnected camera appears as connected device - can't get rid of it!
I recently connected a Samsung Galaxy Tab (SCH-I905) to my Mac, and because it had a photo on it, iPhoto started up and wanted to import the photo. I did that, and ejected the device and all seemed well. But now whenever I start up iPhoto, the SCH-I
-
What can i do if OSX mountain lion download start but never ends?
I need a help urgently
-
Is P6 R8 Compatible with PPM 8.0 ?
Hi, I would know if someone tested the compatibility of PPM 8.0 with P6 R8 (by the Bridge ) I will not upgrade to P6 R8, but this info could be useful on some customer site. Thanks Fabio D'Alfonso http://www.fabiodalfonso.com
-
Diff between searchhelp se11,pov
Hi all, I have a provide a f4 help to one of my fields in the screen. Iam planning to use search help for that field . But do i need to use PROCESS ON VALUE-REQUEST. OR SEARCH HELP. WHATS THE DIFFERENCE BETWEEN THESE TWO. let me know
-
Indesign CC - All menu items greyed out on new install
Hello! I just installed Indesign CC on a new Mac laptop (I can provide specs if needed), and when I open ID *all* menu items are greyed out. I can't create a new file, open legacy files, or even quit the app (force quit only). I have not installed an