Ignoring text enclosed in quotes

Here's a teaser for all you Java whizzes out there. I'm developing an application which shall process html files. Part of the processing requires me to be able to identify function names, variable names, comments etc (in the script). Now here's the catch - I obviously want to ignore any characters which are enclosed in single quotes or double quotes
e.g. document.location.href = "http://blah.com"
My application as implemented, mistakes //blah.com as a comment!
I tried:
private boolean checkDouble(int idx)
Vector vQuotes = new Vector(1,1);
int idxQuote;
int lastQuote = 0;
int quoteCtr = 0;
int curr;
int prev;
String str = null;
String strQuote = "\"";
// store all the positions of the " characters
idxQuote = txt.indexOf(strQuote, lastQuote);
while (idxQuote != -1)
quoteCtr++;
vQuotes.setSize(quoteCtr);
vQuotes.setElementAt((new Integer(idxQuote)), quoteCtr-1 );
lastQuote = idxQuote+1;
idxQuote = txt.indexOf(strQuote, lastQuote);
} // end while
prev = -1;
// does idx lie btn 2 quotes?
for (int i = 0; i < vQuotes.size(); i++)
str = vQuotes.get(i).toString();
curr = Integer.parseInt(str);
if (i == 0)
prev = curr;
if (i == 0 && idx < curr) // before the first quote?
return false;
if ((idx < curr) && (idx > prev) && ((i+1) % 2 == 0))
return true;
prev = curr;
return false;
} // end checkDouble
.... but I had forgotten about the single quotes!!
e.g. function printMessage() {
document.write('hello "world');
... shall trick my app. into considering the whole block of text from "world to the next double quote, as a string.
I hope someone can see the light thru my somewhat cloudy explanation! Please help!

Hi,
you can use a StringTokenizer for this purpose like this
public String extractFromString(String s,String delimiter) {
StringTokenizer st = new StringTokenizer(s,delimiter);
StringBuffer sb = new StringBuffer();
boolean outside = true;
while (st.hasMoreTokens())
String p = st.nextToken();
if (outside) { sb.append(p); }
outside = !outside;
return sb.toString();
}Hope this helps - it does not handle paired delimiters, but it will give you an idea how to do it with a StringTokenizer - any delimiter switches the mode to ignore or not ignore here.
greetings Marsian

Similar Messages

  • Regexp_replace, but not enclosed in quotas

    select regexp_replace(q'#Can I use 'ORACLE :regular :expressions' to replace all :words starting with a :colon with an :asterisk but only if they are not enclosed in 'single quotas'?#',':\w+','*') txt from dual;
    TXT
    Can I use 'ORACLE * *' to replace all * starting with a * with an * but only if they are not included in 'single quotas'?the simple code above replaces too much for my purpose. Is it possible to modify the regular expression in a way that it ignores the words ':regular' and ':expressions' because they are in a part of the text enclosed in quotas?
    By the way: When I run this query in SQL*Developer I get a strange error message:
    SQL-Fehler: Fehlender IN- oder OUT-Parameter auf Index:: 1 (something like SQL-Error: missing IN or OUT parameter on index::1)but when I run it in SQL*Plus it works as expected. Has someone here an explantion for this message or should I start a new thread in the SQL*Developer forum?

    No, expected output is this:
    Can I use 'ORACLE :regular :expressions' to replace all * starting with a * with an * but only if they are not included in 'single quotas'?the first two words with a colon should not be replaced, because they are between the single quotas.

  • Importing Data enclosed in quotes

    Hi all,
    Im trying to import a load of data into my application via the import utility, that is in a comma seperated text file. Many of the data values are lines of text which can also contain commas, so therefore each data value is enclosed in quotes to retain these values and ensure the column ordering when the data is imported.
    For example:
    column1, column2, column3
    "value1", "value2", "value3" -- row 1
    "value4", "value5", "value6" -- row 2
    If I import this data into my app, each data value is still enclsoed by the quotes, which I dont want. So my question is, is there any way to strip out these quotes as the data is being imported to just leave value1 etc. in my table and not "value1" ?

    Dear user512101
    <p>
    did you ever find a solution to this problem? Anyone?
    <p>
    I am facing the exact same issue on a regular basis. So far, I have been "cheating" by importing data through the ODBC connection, using an MS Access client that is still limping along (not for long, says my DBA).
    <p>
    If I don't, a typical column would look something like this:<p>
    "Exceptional biological diversity, WPC ecoregion reference for 71i, Old Hickory Lock 5 Wildlife Refuge "<p>
    "Chickasaw State Forest, Wildlife Management Area and State Park"<p>
    "Federal endangered Birdwing Pearlymussel, Fine-rayed Pigtoe, Shiny Pigtoe, Cumberland Monkeyface, Cracking Pearlymussel, Boulder Darter, and state threatened Ashy Darter." <p>etc. etc.
    <p>
    Vojin

  • StringTokenizer: don't use delimiter when enclosed in quotes?

    I read values from a CSV file via StringTokenizer. The delimiter is the semicolon (;). However, if values contain this delimiter as (part of) value, the value itself is enclosed in double quotes (e.g. "one; two"). The StringTokenizer now detects 2 tokens instead of one:
    "one
    and
    two"
    . Is there a way to tell StringTokenizer to ignore delimiters when in quotes strings?

    You might want to look at InputStreamTokenizer which is rather more sophisticated.

  • Getting parseException if filename is not enclosed within quotes.

    My Client has sent attachment with filename encoded in iso-8859-2. When I parse the mail using javamail, i had ended up parseException. Below is the header and exception details.
    header:
    Content-Type: application/pdf; name==?iso-8859-2?b?RmFrdPpyYV9GQTE0MDE5LnBkZg==?=
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename==?iso-8859-2?b?RmFrdPpyYV9GQTE0MDE5LnBkZg==?=
    Exception:
    javax.mail.internet.ParseException: Expected parameter value, got "="|
    [13:29:47:905]|[06-12-2014]|[SYSOUT]|[INFO]|[log]|[557]: at javax.mail.internet.ParameterList.<init>(ParameterList.java:262)|
    [13:29:47:905]|[06-12-2014]|[SYSOUT]|[INFO]|[log]|[557]: at javax.mail.internet.ContentDisposition.<init>(ContentDisposition.java:100)|
    [13:29:47:905]|[06-12-2014]|[SYSOUT]|[INFO]|[log]|[557]: at javax.mail.internet.MimeBodyPart.getFileName(MimeBodyPart.java:1136)|
    [13:29:47:906]|[06-12-2014]|[SYSOUT]|[INFO]|[log]|[557]: at javax.mail.internet.MimeBodyPart.getFileName(MimeBodyPart.java:513)|
    But when i read RFC 2183, it doesnot tell that the filename must be enclosed within quotes.
    But in the parameterList class you are expecting all the field values have to be enclosed within quotes.
    Please check and correct this.
    Manimekalai

    Your client's software is broken, please tell them to fix it.
    The MIME spec is very clear that parameter values containing certain special characters, including "=", must be quoted.

  • How to pass presentation variable with enclosing single quotes

    HI All,
    As all of you know in 11g, Presentation variable can hold more than one value.So we can pass multiple values to the report through presentation variable.
    If we select x,y,z values from prompt drop down,then those values will be stored like x,y,z in the presentation variable.
    but I would like to store these values with enclosing single quotes like 'x,y,z'
    The reason is I need to pass this variable value as input to BI Publisher sql dataset query where clause.
    Please share your Ideas.
    Thanks,
    Aravind

    Aravind,
    Check this
    Predefined Presentation Variables in OBIEE 11G | Praveen&amp;#039;s Blog

  • Conditional build tags with character styles and ignored text

    RoboHelp HTML v8.0.2.208
    Windows XP Professional Version 2002 Service Pack 3 with 2 GB of RAM
    Output: WebHelp and HTML Help
    I have recently moved my projects from RH HTML X5 to RH HTML 8 and this is when the following problem appeared. I use lots of conditional build tags within the help projects. Some of these tags are for my own use for reference and I combine these with character styles containing a coloured background (highlight) so that they show up in the WebHelp or HTML Help output (e.g. text to identify the software version that the field/feature/text was added, reminders to check details, insertion of bug ID numbers, design document names, etc.). These areas of text are stripped out of the final build for customers by using a conditional build expression.
    What I have noticed is that if a paragraph contains text with a conditional build tag applied AND that tagged text has a character style applied AND an unknown word within the conditional build tag is ignored (with the HTML tag <?rh-ignored text="word_to_be_ignored" ?>), saving the topic, closing it, then re-opening it shows that the conditional build text has stretched to the next conditional build tag, or to the end of the topic if there aren’t any other conditional build tags. This also happens by switching from Design View to HTML View. Note that this doesn’t happen if Ignore All is applied to the unknown word.
    This doesn’t just apply to projects converted from RH X5. I created a new test project in RH8 and the same behaviour was observed. Similar behaviour occurred very occasionally in RH X5 but that seemed to be down to HTML tags being nested incorrectly.
    The largest project contains around 1200 topics and with many hundreds of conditional build text areas this now causes a problem. I’ll probably have to locate every ignored word in an area of conditional text within each project, set it to Ignore All and then manually remove and re-apply the conditional build tags, unless someone can come up with something clever. Can anyone else replicate this and should it be logged as a bug?

    Hi Daggins,
    Thanks - that is good info to have. But as we all agree, that does take away from the point of single-sourcing.
    You aren't misunderstsanding exactly... I am doing all my conditional tagging in FM and it works like a charm in terms of the PDFs that I generate from FM, and even the conditionally tagged text in RH shows/hides correctly. The issue is I am also importing my index and TOC from FM... and even if I have an entire file in FM tagged as conditional (all the text is tagged as conditional, I don't know if you can tag a file as conditional), the file name as a heading it still appears in the RH TOC. There is no text... but in my view it shouldn't appear in the TOC either (it looks like just a broken link when I generate my online help) - this is not ideal.

  • Copy Text from one quote to another

    Hi
    I need to copy text/notes related to one quotation to another.. I tried FM SAVE_TEXT and CRM_TEXT_MAINTAIN_OW but neither of it worked...
    Can anyone help me with this ?

    Hi Ashwineee,
    U can copy text from one quote to another by customizing also
    Just Check the settings of your text type in the text determination procedure.
    Select ur  text type and click on details u will find the text id description sequence and
    Transfer  field u have various options  u select the option "B" for ur text type .
    U can take reference of the  Standard Text determination Procedure "ORDER001"  for doing the same
    for your text determination Procedure
    Menu Path--
    Crm-Basic Functions- Text Management-Define Text Determination Procedure - select the Object --
    example for CRM_ORDERH and click on Procedure and select ur text determination procedure --     
    Select  Definition of Procedure that gives u details of  your   text type  and  its  options
    Hope it will Resolve ur problem
    Regards
    Pavan.A

  • Type on a path ignores text wrap around objects?

    Indesign CS3: type on a path ignores text wrap around objects?
    is this true? or do I have a setting that I'm missing?
    thanks.

    Seems that it does, and in CS4 as well.
    What are you doing with type on a path that requires it to honor wrap? Could you do it by cutting the path and threading?

  • Spaces in property values result in values bein enclosed in quotes (Linux)

    G'day,
    I couldn't find this mentioned in the bugs database (or anywhere else) so it might be a new bug.
    If a property value in a JNLP descriptor contains spaces then the resulting property value returned by System.getProperty() is enclosed in quotes, e.g.
    <property name="jnlp.blah" value="foo bar"/>
    results in System.getProperty("jnlp.blah") returning the value +{color:#ff0000}"{color}foo bar{color:#ff0000}"{color}+ instead of the expected foo bar (without quotes).
    In the Java console I see the following:
    jnlpx.vmargs = {color:#ff0000}"{color}-Xmx512m -Xms256m ... -Djnlp.blah={color:#ff0000}\"{color}foo bar{color:#ff0000}\"{color} ... {color:#ff0000}"{color}
    This only affects Linux (tested with JRE 6.0_20 on Ubuntu 10.04). The same JNLP launched with Java Web-Start on Windows (JREs 6.0_12 & 6.0_21 on Vista) produces the following:
    jnlpx.vmargs = -Xmx512m -Xms256m ... {color:#ff0000}"{color}-Djnlp.blah=foo bar{color:#ff0000}"{color} ...
    So, the problem stems from the way property values with spaces are handled by the Linux implementation of the JRE.
    Has anyone else come across this behaviour?
    Regards,
    Chris.

    G'day,
    AndrewThompson64 wrote:
    If there is one, the best thing to do is raise a bug report, but first you'll need a test case.
    Something with source, JNLP and build file provided. In fact, if you can produce that in a Zip archive available on the net, I can download it and run it both Win 7 & Ubuntu for a further test. Good call - narrowing down a test-case helped me pin down the problem.1. Download the test-case here.
    2. Unzip to /tmp:
    cd /tmp
    unzip JnlpPropertyWithSpacesBug.zip
    3. Test 1:
    javaws file:///tmp/JnlpPropertyWithSpacesBug/test.jnlp
    This should result in the message: System.getProperty("jnlp.my.property") returns null
    This is the correct result.
    4. Test 2:
    javaws /tmp/custom.jnlp
    On Linux, this should result in the message: +System.getProperty("jnlp.my.property") returns {color:#ff0000}"{color}should not be enclosed in double-quotes{color:#ff0000}"{color}+
    This result is incorrect (shouldn't have double quotes).
    Note that custom.jnlp is a customized version of JnlpPropertyWithSpacesBug/test.jnlp:
    1. attributes have been added to the java tag
    2. a property tag has been added for a secure property: sun.java2d.noddraw
    3. a property tag has been added for a jnlp property: jnlp.my.property
    All three are needed to produce the bug. It only occurs on when the Linux JRE is used (6.0_20; Ubuntu 10.04).
    This simulates the situation in which a custom JNLP descriptor is dynamically generated, e.g. to invoke the application with custom system properties.
    There will be extra chance of test results if you can provide a link directly to the JNLP file on the net. The test case would need to be small and sand-boxed, of course.Any suggestions as to where you can freely host Java Web-Start applications?
    Thanks,
    Chris.
    Edited by: cpudney on Aug 18, 2010 2:06 PM

  • How can I replace a text/range of text enclosed in a XML tag

    I want to replace a piece of text enclosed inside a XML tag in a text frame.
    In my input parameters, I have the In-design document page number, text frame UID in that page and the XML tag name inside that text frame
    which encloses my old text.
    what command/function/interface can I use which can help me to replace the existing text with the input text ?
    eg:
    [old text]  -----> [new text]
    where [ ] is XML tag with name tag1.

    After some trail and POC, I was able to write the below piece of code.
    This detects the starting and ending position of the marker and based on that we can replace the text inside it. Hope it helps.
    InterfacePtr<IDocumentSignalData> data(signalMgr, UseDefaultIID());
            if (data == nil)
                break;
            UIDRef docRef = data->GetDocument();
            InterfacePtr<IDocument> doc(docRef, IID_IDOCUMENT);
      IDataBase *db = docRef.GetDataBase();
      //Get the spread
      InterfacePtr<ISpreadList> spreadList(doc, UseDefaultIID());
      int32 spreadCount = spreadList->GetSpreadCount();
      for ( int32 spreadIndex = 0; spreadIndex < spreadCount; spreadIndex++ )
      // Get the spread reference
      UIDRef spreadUIDRef(db, spreadList->GetNthSpreadUID(spreadIndex));
      // Get the spread object
      InterfacePtr<ISpread> spread(spreadUIDRef, UseDefaultIID());
      int32 numberOfPages = spread->GetNumPages();
      for (int32 nPage = 0; nPage < numberOfPages; nPage++ )
      UIDList pageItemList(db);
      spread->GetItemsOnPage(nPage, &pageItemList, kFalse, kFalse);
      // Iterate the page items and save off the UIDs of frames.
      int32 pageItemListLength = pageItemList.Length();
      for (int32 j = 0; j < pageItemListLength; j++ )
      UIDRef pageItemRef = pageItemList.GetRef(j);
      InterfacePtr<IFrameType> frame(pageItemRef, UseDefaultIID());
      if( frame->IsTextFrame() )
      //Now trying to get the marker position for XML tag
      TextIndex startPos=0,endPos=0;
      IXMLReferenceData *xmlReferenceData= Utils<IXMLUtils>()->QueryXMLReferenceData(pageItemRef);
      XMLReference ref = xmlReferenceData->GetReference();
      //IIDXMLElement *element = ref.Instantiate();
      InterfacePtr<IIDXMLElement> element(ref.Instantiate());
      UID tagUID = element->GetTagUID();
      WideString elementName = element->GetTagString();
      for(int32 i=0; i < element->GetChildCount(); i++)
      XMLReference childRef = element->GetNthChild(i);
      InterfacePtr<IIDXMLElement> child_element(childRef.Instantiate());
      tagUID = child_element->GetTagUID();
      elementName = child_element->GetTagString();
      int32 index=0;
      Utils<IXMLUtils>()->GetElementMarkerPositions(child_element,&startPos,&endPos);
      startPos += 1; // move forward to exclude the starting tag
      } // iterate pages in spread

  • SSIS importing comma delimited with double quote text qualifier - Works in VS - SQL Job ignores text qualifier and fails (truncation)

    I've created an SSIS package to import a comma delimited file (csv) with double quotes for a text qualifier ("). Some of the fields contain the delimiter inside the qualified text. An example row is:
    15,"Doe, John",IS2,Alabama
    In SSIS I've specified the text qualifier as ". The sample output in the connection manager looks great. The package runs perfectly from VS and when manually executed on the SSIS server itself. The problem comes when I schedule the package to run via SQL
    job. At this point the package ignores the text qualifier, and in doing so pushes half of a field into the next available column. But instead of having too many columns, it concatenates the last 2 columns ignoring the delimiter. For example (pipes are fields):
    15|"Doe| John"|IS2,Alabama
    So the failure happens when the last half of a field is too large to fit into the next available field. In the case above _John" is 6 characters where the IS2 field is char(3). This would cause a truncation failure, which is the error I receive from the
    job history.
    To further test this I created a failure flow in my data flow to capture the records failing to be pulled from the source csv. Out of ~5000 records, ~1200 are failing, and every one of the failures has a comma delimiter inside the quoted text with a 'split'
    length greater than the next ordinal field. The ones without the comma were inserted as normal and records where the split fit into the next ordinal column where also imported, with the last field being concatenated w/delimiter. Example records when selected
    from table:
    25|"Allan Percone Trucking"|GI6|California --Imported as intended
    36|"Renolds| J."|UI6,Colorado --Field position offset by 1 to right - Last field overloaded
    To further ensure this is the problem, I changed the csv file and flat file connection manager to pipe delimited, and sure enough every record makes it in perfectly from the SQL job execution.
    I've tried comma delimited on the following set ups. Each set up failed.
    SSIS Server 2008 R2 RTM
    DB Server 2008 RTM
    DB Compat 80
    SSIS Server 2008 R2 RTM
    DB Server 2008 R2 RTM
    DB Compat 80
    SSIS Server 2008 R2 RTM
    DB Server 2008 RTM
    DB Compat 100
    SSIS Server 2008 R2 RTM
    DB Server 2008 R2 RTM
    DB Compat 100
    Since a lot of our data comes in via comma delimited flat files, I really need a fix for this. If not I'll have to rebuild all my files when I import them to use pipe delimiters instaed of commas. I'd like to avoid the extra processing overhead if possible.
    Also, is this a known bug? If so can someone point me to the posting of said bug?
    Edit: I can't ask the vendor to change the format to pipe delimited because it comes from a federal government site.

    Just wanted to share my experience of this for anyone else since I wasted a morning on it today.
    I encountered the same problem where I could run the package fine on my machine but when I deployed to a server and ran the package via dtexec, the " delimeter was being replaced with _x0022_ and columns all slurped up together and overflowing columns/truncating
    data etc.
    Since I didn't want to manually hack the DTS XML and can't install updates, the solution I used was to set an expression on the textdelimiter field of the flat file connection with the value "\"" (a double quote). That way, even if the one stored in XML
    gets bodged somewhere along the way, it is overridden with the correct value at run time. The package works fine everywhere now.

  • Gmail message text box does not show up when I click on message to read it. Text will appear quoted if I click in Reply box.

    When I open Gmail, I get the usual list of messages. When I click on a message to read it, everything appears as usual except the box with the message text in it. To see that text, I have to click in the Reply box, and then I'll see the original message text quoted.
    This is true on three different Gmail accounts. I've not changed any Gmail settings. I have enabled and disabled various extensions and User Styles that affect Gmail, and turned off Greasemonkey, without effect.
    Yesterday I did update Java 7 update 10, but Gmail was still working after that. I did install several new extensions at that time, but I tried disabling them and restarting, and the problem persisted.
    Please help. Thanks.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Button wont work with Text in the way, code to ignore text?

    Hey, I'm createing a menu but the text on button stops button animation on click, is there code to ignore the text? I dont want to have to create a new graphic for every button I've tried grouping but that didnt help please help me!! (Awesome product btw Adobe, love you long time)
    Emma

    Yeah I thought of that, just the animation is inside the button symbol and the text is outside. I have heaps of instances of the same button, so if I put the text inside the symbol for button obviously it will go on every instance.
    How would I code an invisible button to play inside the button symbol from the main timeline? Sorry been a long time since I was coding in flash, lol and very new to edge, guess cos it's new... lol
    So I would have the invisible area to click on the main timeline and I would want to code that to play the timeline inside the button symbol. Hopefully that makes sense.

  • JS - surrounding selected text with double quotes

    I have a working script which places brackets around selected text in the main body of my document (not in a table), but when I changed the script to insert double curly quotes, the script wont work.
    Why wont this JS work (script stalls on the var line):
    var myObject = (app.selection[0].parent.constructor.name == "Cell") ? app.selection[0].parent.texts[0] : app.selection[0];
    with (myObject)
    insertionPoints[-1].contents = "";
    insertionPoints[0].contents = "";
    while this one does work:
    var myObject = (app.selection[0].parent.constructor.name == "Cell") ? app.selection[0].parent.texts[0] : app.selection[0];
    with (myObject)
    insertionPoints[-1].contents = ")";
    insertionPoints[0].contents = "(";
    Thx Oz
    PS The quotes are showing as three straight quotes above, but in my script they are two straight double quotes surrounding either a right or a left curly double quote.

    Perhaps there's a Smart Quotes interpreter in JS? Who knows.
    If you find it failing again, try inserting the quotes as Unicode values, as these should not be subject to any translating.
    I.e.,
    >insertionPoints[-1].contents = "\u201c";

Maybe you are looking for