Problem formating StringBuffer/Text with Properties

Hi my Java good Freinds,
I have the following toString BufferedString named buf which i got from reading my serialPort getInputStream:
0111XXX01XXX0001XXX01XXXXXXX11XXX000XXXXXXX110XXX111XXX111XXX100
and i have the following Properties file named "proptab":
0111=J
01=A
0001=V
11=I
000=S
110=G
111=O
100=D
i used the following pseudo code to format/translate the buffered String in order to get the following:
JAVA IS GOOD
String str = buf.toString();
StringBuffer result = new StringBuffer();
int pos;
int count=0;
String output="";
table = new Properties();
try {
FileInputStream morsehashinput;
tabinput = new FileInputStream( "proptab" );
table.load( tabinput );
tabinput.close();
catch( IOException ex ) {
System.out.print("File not found");
if((pos = tmp.indexOf("XXX")) != -1) {
result.append( table.getProperty(str.substring(count,pos)) );
count = += pos;
if((pos = tmp.indexOf("XXXXXXX")) != -1) {
result.append(" ");
output = result.toString();
JOptionPane.showMessageDialog( null, output,
"Demonstrating String Class \"index\" Methods",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
when i run this code instead of getting JAVA IS GOOD, i only get J
please i want to know what is wrong with the code or preferably another better way to retrieve and translate the data from the buffered String

The reason you only get 1 character is that you only process one substring. You need a loop construct.
Use StringTokeniser for these easy parsing operations.
    String s = "0111XXX01XXX0001XXX01XXXXXXX11XXX000XXXXXXX110XXX111XXX111XXX100";
    Map map = new HashMap();
    map.put("0111","J");
    map.put("01","A");
    map.put("0001","V");
    map.put("01","A");
    map.put("0111","I");
    map.put("000","S");
    map.put("110","G");
    map.put("111","O");
    map.put("100","D");
    StringTokenizer st = new StringTokenizer(s,"XXX");
    while (st.hasMoreTokens()) {
      String token = st.nextToken();
      if (map.containsKey(token))
        System.out.print(map.get(token));
      else
        System.out.print(" ");
    }BTW you've got some empty substrings in your source string, you may want to consider putting in expressions for blanks like "0" = " ".
Dave

Similar Messages

  • Formatting incoming text with style sheets

    Is there a way to "find/change" formatted text with existing style sheets?<br /><br />In other words I have formatted text placed into my indesign document that looks like the following: <bf>Four Patch</bf> Then another set of text that looks like this:<it> Baltimore Press</it> <br /><br />I set up stles sheets formatted for Bold font and Ital font to accomodate these formats. Problem is I have a 500 page book that I need to go through and stylize. I tried to do a find/change global (<bf> </bf> to bold font etc but it didn't work. I was hoping by just putting a space between the <> would  help the find/change option to find all the text but kept saying could find.<br /><br />I hope someone understands what I'm trying to do and can tell me that there is a remedy to the tedious formatting issue I have.<br /><br />Thanks<br /><br />MAria<br />Stuart, Florida

    If you have InDesign CS3, I can think of two ways to deal with this.
    Grep search: set search to
    <bf>([^<]+)</bf>
    and replacement string to
    $1
    and then set the change format to your boldface style. Change all. (I often think it's a good idea to take a copy before doing Change All on a 500-page document, but that's up to you.) Repeat with hopefully obvious changes for the italics. You can save the searches if you need to do this often.
    Adventurous alternative.
    Put the single line
    <stuff>
    at the top of your file, and
    </stuff>
    at the bottom.
    Now it's XML. So open the structure panel, import XML from the fly-out menu. Map Tags to Styles from the same menu, and set up the correspondence you need. Then drag the stuff node from the structure panel to the document.
    If you have to do this more than once, you can import the mapping from an old file each time after the first.
    IMPORTANT: The XML route will fail if you have loose & or less than characters in your file. You would have to replace these with the appropriate character entity references.
    (If you aren't reading this on the forum site, you may be seeing character entity references in the message. Hopefully you can decode them.)

  • How format a text with "Justified"?

    Hello!
    I would like to make a photo book (iphoto '08) with lengthy passages of text.
    Does anyone know how I can format a Text in "justified"?
    Siggo

    Create the text in another app - say Pages or TextEdit and set your alingment as you wish. Then copy and paste t the book
    Regards
    TD

  • Problems formatting external drive with Disk Utility

    Hi all
    I'm having some odd troubles with using Disk Utility to format an external hard drive. For some reason, it is giving me all sorts of errors and problems.
    Currently, it will let me format the drive in MS-FAT, but won't let me copy certain files to it (it gives an error code). I'm currently trying to re-format the drive in Mac OS Extended (Journaled) but the status bar give me the following error and continues to do its 'pondering' instead of giving me a progress bar:
    !http://img19.imageshack.us/img19/5019/picture2csm.png!
    It is currently sitting like that, not doing anything (not even going unresponsive).
    What am I doing wrong here?
    Cheers.

    Wait, scratch that, it suddenly started working again.
    For some reason, I had to partition it, with one partition a Mac OS partition and the other an MS-DOS FAT... hey ho, no idea.

  • Problem formatting date labels with DateTimeAxis and parseFunction

    I'm working with a line chart that gets its data from a MySQL
    database and
    I'm using a DateTimeAxis to try to display the date on the
    x-axis. The date
    is formatted in the database as "YYYY-MM-DD" - however when I
    run the
    application I am only seeing the date displayed as MM/YY. I
    am using a
    parseFunction as follows:
    public function myParseFunction(s:String):Date {
    var a:Array = s.split("-");
    var newDate:Date = new Date(a[0],a[1]-1,a[2]);
    return newDate;
    I was trying to experiment with setting dataUnits to days or
    weeks but it
    doesn't seem to change. Can anyone figure out what I'm doing
    wrong?
    Thanks,
    -Dan
    The code for the line chart is:
    <mx:LineChart x="10" id="linechartHist"
    dataProvider="{dataProvider1}"
    showDataTips="true" width="100%" height="100%" y="10">
    <mx:horizontalAxis>
    <mx:DateTimeAxis displayName="Date" title="Date (Month)"
    parseFunction="myParseFunction" dataUnits="days"/>
    </mx:horizontalAxis>
    <mx:horizontalAxisRenderer>
    <mx:AxisRenderer canDropLabels="true"/>
    </mx:horizontalAxisRenderer>
    <mx:verticalAxis>
    <mx:LinearAxis title="Price" id="vAxis"
    labelFunction="vLongLabels"
    interval="10"/>
    </mx:verticalAxis>
    <mx:series>
    <mx:LineSeries displayName="MSFT" yField="MSFT"
    xField="date"/>
    <mx:LineSeries displayName="PG" yField="PG"
    xField="date"/>
    <mx:LineSeries displayName="NTDOY" yField="NTDOY"
    xField="date"/>
    </mx:series>
    </mx:LineChart>

    Hi
    Try using "sv_SE" locale.

  • Is anyone else having problems sending a text with imessage on the 7.0.2 update?

    When ever i send a text message to another friend who has a iphone imessage won't send it and i have to send it as a regular text. any thoughts on what might be the problem?

    Lots of bugs in Mavericks.
    Get the Time Capsule up and running.
    Temporarily, connect a spare Ethernet cable from your Mac to the WAN port on the AirPort that you need to configure to see if that will get you past the "unexpected error".
    Once the device is configured, you can disconnect the Ethernet cable and move the AirPort to the area where it will be needed.

  • Help with creating hyperlinks in formatted CSS text

    I'm having difficulty adding links using Dreamweaver. I first
    format the text with a CSS style, then use the Properties window to
    add the hyperlink (or Insert>Hyperlink menu). It creates this,
    <p class="linkbodyleftcol"><a href="
    http://www.amcc.com">AMCC</a></p>
    However, when I place the cursor on AMCC in the design
    window, most of the CSS styles I see in the CSS Styles menu are
    crossed out with a message "...does not apply to your selection
    because it is not inherited. It is applied to a closing tag."
    To correct this, I modify the code to:
    <a href="
    http://www.amcc.com"><p
    class="linkbodyleftcol"AMCC</p></a>
    And this clears up the error. However, there must be a more
    efficient way to add links while retaining CSS formatting. Could
    someone point out a better method?
    Best regards, -gary

    But wouldn't this still entail adding a hyperlink in Design
    view then editing this code in Code view?
    Doesn't DW allow one to enter a hyperlink in Design view
    while maintaining CSS? Seems hard to believe something so simple
    would require going into the code, since CSS and hyperlinks are two
    key ingredients in web design.

  • Time Format using text variable with replacement path

    Hi Friends,
                                 I've used "Text variable with replacement path" to make the column heading dynamic by replacing the values referring from "0calday"...
    everything is working fine, but here it is displaying the time format like
    YYYYMMDD (20030101), i want it to be displayed DDMMYYYY (01012003) in the column heading... how to make it possible?
    pls waiting for ur inputs, it's an urgent...
    Regards,
    Pattnaik

    Hi Satyakam,
    In the text variable properties make sure that in the replacment path you have chosen "Text" to appear date as per user setting . Other wise as in your case it must be set to "Key" which always shows in the format YYYYMMDD.
    Hope that helps.
    Regards
    Mr Kapadia

  • Problem with Numbers! Cannot format a number with "1000" separator

    I need to format numbers in cells with the "1000" separator 
    1000.99     should really look like        1,000.99
    Looks like there is no way to do this in Numbers!
    I only found the following work-around:
    When I import a spreadsheet from Excel the formating is there and Numbers will even keep the format as long as I do not delete the cell contect! So to me this means that the functionality is there - it was just forgotten to implement a numbers formatting took in the GUI!
    Of course Numbers is just a scaled down product for iPad and does not really stand up to Excel but this is the most basic function that I expected from a spreadsheet program!
    Anybody experience that problem too or is there another way to get this to work?

    Hey Dell,
    I actually fixed this by using the following which gives the same result.
    ToText(Member#,"#") & "-" & ToText(Account#,"#")
    It would be nice if Crystal Reports Server 2008 was able to detect the field formats used in a report when saved from Crystal Reports. This worked without the formulas in Crystal Enterprise 9.
    Another issue I found on this report was an issue with charts and group headers. If you are using a number on your chart axis it was displaying the number as 9,999.00 and the same for the Group Header. You actually have to create a group header and axis formula specifically converting the number to text with the formula above.
    Thanks,
    Lee

  • I had a problem with the hard disk on a 2010 macbook pro. Replaced the hard disk with an Hitachi 1TB and when I tried to erase and format It fails with input/output error. Any help much appreciated!

    I had a problem with the hard disk on a 13" 2010 macbook pro. Replaced the hard disk with an Hitachi 1TB disk but when I tried to erase and format, it fails with input/output error and at other times saying unable to allocate memory. Any help much appreciated!

    Zap the PRAM and Reset the SMC, then try again.

  • I created a pdf form from a Word doc with 9 pt aerial font formatting; the text on the pdf form is aerial 9 pt, but the fields are formatted in courier 12 pt - How do I reformat the font in the fields??

    I created a pdf form from a Word doc with 9 pt aerial font formatting; the text on the pdf form is aerial 9 pt, but the fields are formatted in courier 12 pt - How do I reformat the font in the fields??

    You can set up a temporary button (or link, bookmark, etc.) and add the following JavaScript action:
    // Mouse Up script for a temporary button (or bookmark, etc.)
    // Change the font and font size for all text fields in this document
    for (var i = 0; i < numFields; i += 1) {
        var f = getField(getNthFieldName(i));
        if (f.type === "text") {
            f.textFont = font.Helv;
            f.textSize = 9;
    It also sets the font size, but you can remove that line if you don't need to do that.

  • 'Format Payment Instructions with Text Output' program ending in error

    Hi All,
    'Format Payment Instructions with Text Output' program of the payment cycle is completing in to error.
    error is:
    length of the output - baos::4914
    After formatting, periodicSeq is null or empty.{}
    length of the output - baos::4914
    Exit: iby.scheduler.FDFormatProgramUtils.doExtractAndFormatCommon()
    Saving format output.
    Enter: iby.scheduler.FDExtractAndFormatting.queryFileSysAttributes
    Querying file system output attributes
    ppDir: null
    ppExt: null
    ppPre: null
    File system output settings that override the concurrent program default: {}
    Exit: iby.scheduler.FDExtractAndFormatting.queryFileSysAttributes
    Enter: iby.scheduler.FDFormatProgramUtils.saveToFileSystem()
    Concurrent request output file name: /NGFQ2/oraapps/NGFQ2/inst/apps/NGFQ2_dngfdb25/logs/appl/conc/out/o19301342.out
    Opened file in append mode: /NGFQ2/oraapps/NGFQ2/inst/apps/NGFQ2_dngfdb25/logs/appl/conc/out/o19301342.out
    Exit: iby.scheduler.FDFormatProgramUtils.saveToFileSystem()
    Enter: iby.scheduler.FDExtractAndFormatting.saveFormatOutput()
    Nov 25, 2009 7:59:16 PM oracle.adf.share.config.ADFConfigFactory findOrCreateADFConfig
    INFO: oracle.adf.share.config.ADFConfigFactory No META-INF/adf-config.xml found
    oracle.apps.fnd.framework.OAException: Application: FND, Message Name: FND_GENERIC_MESSAGE. Tokens: MESSAGE = oracle.jbo.ApplicationModuleCreateException: JBO-25222: Unable to create application module.;
    at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:896)
    at oracle.apps.fnd.framework.OAApplicationModuleFactory.createRootOAApplicationModuleInternal(OAApplicationModuleFactory.java:476)
    at oracle.apps.fnd.framework.OAApplicationModuleFactory.createRootOAApplicationModule(OAApplicationModuleFactory.java:608)
    at oracle.apps.iby.util.OAAttachmentServerUtilsWrapper.<init>(OAAttachmentServerUtilsWrapper.java:35)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.saveFormatOutput(FDExtractAndFormatting.java:450)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.doExtractAndFormat(FDExtractAndFormatting.java:421)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.runMainLogic(FDExtractAndFormatting.java:251)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.runProgram(FDExtractAndFormatting.java:141)
    at oracle.apps.fnd.cp.request.Run.main(Run.java:157)
    ## Detail 0 ##
    oracle.adf.mds.exception.MDSRuntimeException: Unable to load metamodel definition because the mmd file file:/NGFQ2/oraapps/NGFQ2/inst/apps/NGFQ2_dngfdb25/logs/appl/conc/log/null/jrad/JRADElementList.xml is invalid.
    /NGFQ2/oraapps/NGFQ2/inst/apps/NGFQ2_dngfdb25/logs/appl/conc/log/null/jrad/JRADElementList.xml (No such file or directory)
    at oracle.adf.mds.internal.ElementData.<init>(ElementData.java:113)
    at oracle.adf.mds.internal.MElementImpl.<init>(MElementImpl.java:480)
    at oracle.adf.mds.internal.jbo.JBODefManagerHelper.getSubstitution(JBODefManagerHelper.java:240)
    at oracle.adf.mds.internal.jbo.JBODefManagerHelper.getSubstitution(JBODefManagerHelper.java:178)
    at oracle.adf.mds.internal.jbo.JBODefManagerHelper.listBindings(JBODefManagerHelper.java:124)
    at oracle.adf.mds.jbo.JBODefManager.listBindings(JBODefManager.java:100)
    at javax.naming.InitialContext.listBindings(InitialContext.java:406)
    at oracle.jbo.mom.DefinitionManager.findSubstituteName(DefinitionManager.java:451)
    at oracle.jbo.mom.DefinitionManager.findDefinitionObject(DefinitionManager.java:411)
    at oracle.jbo.mom.DefinitionManager.findDefinitionObject(DefinitionManager.java:358)
    at oracle.jbo.mom.DefinitionManager.findDefinitionObject(DefinitionManager.java:340)
    at oracle.jbo.server.MetaObjectManager.findMetaObject(MetaObjectManager.java:700)
    at oracle.jbo.server.ApplicationModuleDefImpl.findDefObject(ApplicationModuleDefImpl.java:232)
    at oracle.jbo.server.ApplicationModuleImpl.createRootApplicationModule(ApplicationModuleImpl.java:401)
    at oracle.jbo.server.ApplicationModuleHomeImpl.create(ApplicationModuleHomeImpl.java:91)
    at oracle.apps.fnd.framework.OAApplicationModuleFactory.createRootOAApplicationModuleInternal(OAApplicationModuleFactory.java:428)
    at oracle.apps.fnd.framework.OAApplicationModuleFactory.createRootOAApplicationModule(OAApplicationModuleFactory.java:608)
    at oracle.apps.iby.util.OAAttachmentServerUtilsWrapper.<init>(OAAttachmentServerUtilsWrapper.java:35)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.saveFormatOutput(FDExtractAndFormatting.java:450)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.doExtractAndFormat(FDExtractAndFormatting.java:421)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.runMainLogic(FDExtractAndFormatting.java:251)
    at oracle.apps.iby.scheduler.FDExtractAndFormatting.runProgram(FDExtractAndFormatting.java:141)
    at oracle.apps.fnd.cp.request.Run.main(Run.java:157)
    An error occurred. Roll back any changes.
    Done roll back changes.
    Request completed in error.
    Has anybody came across this error. If yes, what needs to be done to resolve this error?
    Thanks in advance for your help.
    Thanks Again,
    Sachin

    Hi,
    oracle.adf.mds.exception.MDSRuntimeException: Unable to load metamodel definition because the mmd file file:/NGFQ2/oraapps/NGFQ2/inst/apps/NGFQ2_dngfdb25/logs/appl/conc/log/null/jrad/JRADElementList.xml is invalid. Please see if (Note: 556812.1 - R12 Error When Running The Payment Format: JRADElementList.xml is Invalid) is applicable.
    Regards,
    Hussein

  • Problem formatting text

    I have this problem in formatting (I think the correct word is formatting) the text in a table of contents I'm making. What I want to do is the following:
    True out the document I have got these headers that look like this:
    1.2.3. Dit - Is - Text
    Say this subject is covered on page 50 of my document, then the entry in the table of contents should be:
    1.2.3. Dit - Is - Text..................50
    So far so good. But then my problem: underneath this entry is an other one, lets say:
    1.2.3.4. Dit - Is - Text - Ook .....51
    When you see these two below each other, you can see that the text (the D's in "Dit") doesn't line up:
    1.2.3. Dit - Is - Text..................50
    1.2.3.4. Dit - Is - Text - Ook .....51
    What I want to do is more or less the following;
    1.2.3.    Dit - Is - Text..............50
    1.2.3.4. Dit - Is - Text - Ook .....51
    (The D's in "Dit" should line up exactly.)
    I don't want to do this manually because the table of contents might still change so it will be nice if I can do this automatically.
    Does anyone have a clue how I could do this. I took a look at nesting styles, but I don't think the solution is in there (but i might very well be wrong). Some one mentioned grep but I haven't got a clue how to use grep... (and it didn't really seem suitable for my problem.)
    I can imagine it's quite easy, but i'm kind of a novice when it comes to InDesign and computers as a whole.
    I'm using Adobe InDesign CS3 (English version) on a Windows 7 computer.

    I think Peter is going in the right direction (I did just type in the numbers and didn't generate them in a numbered list of some sort). When I type "((\d\.)+)" in the GREP "Find what:" field it finds the "1.2.3." / "1.2.3.4." and so on parts of the paragraph names in my Table of Contents. All i need to do is add a tab after this part of the paragraph name. I think you did explain how to, but i didn't really get it. When I enter "$1\t" in the "Change to:" field the result is something like this:
    (before i do the grep search / change to)
    1.5.1.3. Beheer - Productbeheer - Producten - Prijzen bewerken...63
    (after I do the grep search / change to)
    1.5.1.3. ...........................................................Beheer - Productbeheer - Producten - Prijzen bewerken...63
    Thats in the right direction, but i don't need all the dots, I just need a tab!
    Peter are you Dutch (your name sounds kinda Dutch) because then maybe you could explain to me in Dutch (which would make things a bit easier for me).

  • Copy text with formatting in acrobat api

    Is it possible to copy the text with formatting via plugin api to a file?please provide methods or samples to achieve this functionality.

    Hi Irosenth,Test Screen name, I'm getting issues while formatting ,this pdf
    http://dprs.datamatics.com/ismart/doublecolumn.pdf
    displays results as like
    87  away aside; Q2’s ‘awry’ is generally (‘No, no, not I’, etc). preferred (e.g. by Oxf), presumably as 97 I know F’s reading is less accusatory a rarer and stronger reading, though than Q2’s ‘you know’, which is pre-Hibbard prints ‘away’. Either could be ferred by Oxf. a misreading of the other. 99 *the . . . Then . . . lost Jenkins, Oxf
    89  Nymph . . . orisons Jenkins sees in and Hibbard all conflate to read ‘the Q2/F’s shared spellings evidence of F . . . their . . . lost’. The only word that following Q2. strictly requires emendation is F’s
    96  No, no Hibbard conflates with Q2’s ‘left’ for lost, which seems a likely ‘No, not I’ to produce a metrical line error.
    But it suppose to show as
    Please clear me why the formatting has been lost?what's the alternative in this situation???
    Reply ASAP....THANKS

  • Format Payment Instructions with Text Output issue

    Hi All,
    We have requirement like don't want print checks in oracle, just process the payment, generate the document number(check number) in oracle and send the data file to third party system. It takes care the check printing.
    For this I developed e-text xml template, created the payment format of type Disbursement Payment Instruction, attached to bank account and Payment process profile.
    When I am processing payment it is submitting 'Format Payment Instructions with Text Output' instead of 'Format Payment Instructions' but that program extracting the previous check information which not related to supplier and as well as payments batch.
    Please let me know what would be the issue?
    Thanks
    Praveen

    Hi Javvaji,
    Please check the following steps,
    1) Created XML Pubblisher template and attached the .rtf (Type - eText-Outbound, Default Output Type - eText)
    2) In Payable Manager responsibility Create a Payment Format ->
    Setup-> Payment Administrator-> Formats (Add XML Publisher Template created in step1)
    3) Setup-> Payments -> check existing Bank & Bank Branches
    4) Setup-> Payments -> Bank Accounts -> Create the payment Document Number
    5) Attach the Bank account to a valid supplier: Payables – Suppliers -> Entry
    6) Now to create the payment Process Profile (PPP)
    Navigation : go to Payables -> Setup-> Payment Administrator
    7) Now to attach everything (PPP,format,document etc.) to the Template
    First step to Create a “Template”
    Navigation: Payables,Vision Operations -> Payments -> Entry -> Payments Manager
    8) Then go to Tab “Payment Process Requests” Then click on “Submit Single Request”
    9) Check View -> Requests
    No output generated in 'Format Payment Instruction' program.
    which program I can get the eText output?
    Please suggest.
    Thanks & Regards,
    Sagarika

Maybe you are looking for