Javascript - getting part of a string

I guess this is not a dreamweaver question per se, more
strictly javascript
but I know a lot of people here are pretty well versed so I
hope it is ok
if I ask here.
I have the strings
Method1 ($5.49)
Method2 ($9.99)
I wish to retrieve just the numerical values and assign them
to variables.
So I guess in pseudocode what I want is to get whatever lies
between the
character strings '$' and ')' leaving me with 5.49 and 9.99
respectively.
I've been fiddling with str.match and other regular
expression things which
I do not fully understand and so far no luck.
Any help is much appreciated.

I know about regexp but don't know how to do what I need.
Anywhere in
particular you know of that can explain it? I've been stuck
trying to
figure it out for quite a while now.
"Franz Marksteiner" <[email protected]> wrote
in
news:f4diu5$7of$[email protected]:
> "E Eds" <[email protected]> schrieb im Newsbeitrag
> news:[email protected]..
>>I guess this is not a dreamweaver question per se,
more strictly
>>javascript
>> but I know a lot of people here are pretty well
versed so I hope it
>> is ok if I ask here.
>>
>> I have the strings
>>
>> Method1 ($5.49)
>> Method2 ($9.99)
>>
>> I wish to retrieve just the numerical values and
assign them to
>> variables.
>>
>> So I guess in pseudocode what I want is to get
whatever lies between
>> the character strings '$' and ')' leaving me with
5.49 and 9.99
>> respectively.
>>
>> I've been fiddling with str.match and other regular
expression things
>> which
>> I do not fully understand and so far no luck.
>>
>> Any help is much appreciated.
>
> Try to read into "RegExp" (Regular Expressions).
> RegExp will allow you to specify some pattern, and
extract parts (in
> your case the numerical ones) of it.
>
>

Similar Messages

  • Getting parts of a string (using regexp_instr, REVERSE, ...)

    Hi,
    I'm trying to alter our company's existing procedure, so that it can extract the Nr of the house, and the bus ('mailbox') from the field "pio_address.street_nr_bus".
    Now, if the input is something simple like "Testlane 15 A", there's no problem ofcourse, but since the data comes from what people entered in a form (on our site for example), it can get really messy and the input might be like:
    [streetpart1] [streetpart2] [streetpart 3] [NR] [NRpart2] [mailbox] ==> ex: "Test 2 Lane 15 B A"
    So in that example, I'd like to get "15 B A" (being a combination of house-nr and mailbox-nr)
    So what I've come op with for now (would love to simplify it though) is the following code; but the procedure takes 30 minutes to complete now (~7000 records), which seems rather long, especially since it used to last like 5-10 minutes.
    Any ideas/tips?
    code:
    SELECT REGEXP_REPLACE(trim(REVERSE(pio_address.street_nr_bus)),' *',' ') INTO pio_address.street_nr_bus
    FROM DUAL;
    SELECT REGEXP_INSTR(pio_address.street_nr_bus, '[[:digit:]]') INTO v_posnr FROM DUAL;
    SELECT REGEXP_INSTR(pio_address.street_nr_bus, '[[:alpha:]]', v_posnr) INTO v_posstreet FROM DUAL;
    IF v_posstreet = 0 THEN
    SELECT REVERSE(pio_address.street_nr_bus) INTO v_nrbus FROM DUAL;
    ELSE
    SELECT trim(REVERSE(substr(pio_address.street_nr_bus,1, v_posstraat-1))) INTO v_nrbus FROM DUAL;
    END IF;
    *****UPDATE*****
    it appears that this part of the code isn't what's slowing the procedure down, but if someone still knows a "shorter" way to accomplish what I'm doing with this code, tips are always welcome
    Edited by: user11236545 on Mar 27, 2012 2:47 AM
    Edited by: user11236545 on Mar 27, 2012 2:49 AM

    thanks, normally that would have been a great solution!
    ...buuuut I've just got some more examples of what my input might be, and instead of just 'Test 2 Lane 15 B A'
    it could also be something like 'Test 2 Lane 15B BUS 2'
    so, since the last character can also be a number ...
    this is what I've got atm:
    SELECT REVERSE(REGEXP_REPLACE(UPPER(pio_adres),'POSTBUS|BUS',''))
    INTO pio_adres FROM DUAL;
    SELECT REGEXP_REPLACE(trim(pio_adres),' *',' ') INTO pio_adres
    FROM DUAL;
    SELECT regexp_instr(pio_adres, '[[:alpha:]]{3,50}')
    INTO v_streetpos FROM dual;
    Now, like before, when using the old source; running the procedure takes 5minutes;
    and running the new source (with this piece of code added), it takes like 35 minutes...
    I'm testing it on about 7000 records, so yeah, the procedure suddenly has to do 3 extra selects 7000 times, but 30 minutes extra is waaaay too long. It doesn't seem normal to me, does it?

  • Get part of string

    I have the following string:
    jdbc:odbc:dbName
    I wish to get "dbName" from the string?

    I have the following string:
    jdbc:odbc:dbName
    I wish to get "dbName" from the string?Parse it. :)
    If the string always is constructed as follows:
    <string>:<string>:<string>
    Then you can just split it with regular expressions or with the stringtokenizer:
      String dbName = "jdbc:odbc:dbName".split(":")[2];

  • Converting part of the string to a date and subtract with sysdate.

    HINT! In order solve this you must know how the pnr is assembled. Study this:
    650323-5510, we only need the first six characters. They inform us about when the person (car owner) was born. In this case it is 23 Mars 1965. You have to use several oracle built-in-functions to solve this. Hint! Begin by converting part of the string to a date and subtract with sysdate.
    select to_char(to_date(cast(pnr,'YYMMDDMM'))) from car_owner;
    please what am i doing wrong. i need the result to be something like this
    Hans, Rosenboll, 59,6 years.

    Hi.
    The main problem here is you have only last two digits of year. That could be the problem in a couple of years from now, when somebody born after 2k would get in to your database. For now if we ignore this problem the right solution would be :
    <code>
    SELECT months_between(trunc(SYSDATE),
    to_date('19' || substr('650323-5510',
    1,
    6),
    'YYYYMMDD')) / 12 years_old
    FROM dual
    </code>
    Suppose you are expecting the age of the car owner as a result above code will give you that. One again notice the '19' I appended.
    Best regards.

  • JAXB unmarshalling error for " " token as part of xsd:string type element

    JAXB unmarshalling error for "<" token as part of xsd:string type element
    We are getting a JAXB unmarshalling error:
    while processing the following <condition> tag which is of type xsd:string
    <condition> x < 100 </condition>
    The error is probably happening due to "<" token as a part of string type.
    xml.bind.JAXBException: Unexpected error in Unmarshalling
    at oracle.xml.jaxb.JaxbUnmarshaller.unmarshal(JaxbUnmarshaller.java:224)
    Any ideas how to resolve this issue?
    Note
    <condition> x > 100 </condition> is getting unmarshalled successfully by JAXB unmarshaller.
    Thanks

    Hi,
    Did you tried to put & lt; (without space) instead of < ?
    Best Regards,
    Paweł

  • Delete part of a string question

    Hello I have this String 12a
    I need to get a the value 12 of it an make it an int
    But the problem is that I don't know what the string is it can be
    12
    or 12 a
    or 12a
    It is for people to fill in there house address and this is the number part.
    The string is like this String number ="\"12a\"";
    Is it possible to look for a letter in a String and delete it if you only want ints???

    Try this on the command line. Dealing with java.lang.NumberFormatException in cases where the number is too large is left as an exercise.
    Harald.
    import java.util.regex.*;
    * demonstrates use of <code>java.util.regex</code> to check if a
    * string starts with digits.
    public class bla {
       * thrown by {@link #getNumber} if the given string does not start
       * with digits.
      private static class BoomBoom extends Exception {
        public BoomBoom(String msg) {super(msg);}
       * reusable pattern to check for digits.
      private static Pattern p = Pattern.compile("[0-9]+");
       * convert leading digits of the parameter to an <code>int</code>
       * and return it.
       * @throws BoomBoom if the parameter does not start with digits.
      public static int getNumber(String s) throws BoomBoom {
        Matcher m = p.matcher(s);
        if( !m.lookingAt() ) {
          throw new BoomBoom("The string `"+s+"' does not start with "
                    +"a positive number.");
        return Integer.parseInt(m.group(0));
      // don't clutter the javadoc
      private bla() {}
       * passes each command line argument through {@link #getNumber} and
       * prints the output or error to <code>System.out</code> or
       * <code>System.err</code> respectively.
      public static void main(String[] argv) {
        for(int i=0; i<argv.length; i++) {
          try {
         System.out.println("Your string `"+argv[i]
                      +"' starts with number "
                      +getNumber(argv));
    } catch( BoomBoom e ) {
         System.err.println(e.getMessage());

  • How Do I Mirror A Part Of A String?

    Dear Programmers,
    Does Anyone know how to mirror a string in C#:
    For example:  looks -> skool
    Thank you in advance,

    There is a Reverse method:
    string s = "looks";
    s = new string(s.Reverse().ToArray());
    Best way to reverse a string:
    http://stackoverflow.com/questions/228038/best-way-to-reverse-a-string
    And you can get a part of a string using the Substring method:
    https://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.110).aspx
    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question.

  • Using INSTR to extract part of the string ?

    Morning guys and Happy Friday.
    I have a situation where I have to pull out part of the string using a select statement.
    Here is the string and I have to get the contents between the 2nd and 3rd backslash. So, basically, I have to extract marypoppins. Any ideas ?
    C:\USERS\marypoppins\Docs\SpecificationHere is where I started ... and I have stumbled upon trying to find the 3rd backslash. I can easily start the INSTR at 4 because I know that it will always be 'C:\'
    select select substr(C:\USERS\marypoppins\Docs\Specification',
                                INSTRB('C:\USERS\marypoppins\Docs\Specification', '\', 4), .....) from dual;

    Additionally you can break it all up simply with regular expressions..
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'C:\USERS\marypoppins\Docs\Specification' as txt from dual)
      2  -- END OF TEST DATA
      3  select rownum, regexp_substr(txt, '[^\]+',1,rownum) as element
      4  from t
      5* connect by rownum <= length(regexp_replace(txt,'[^\]'))+1
    SQL> /
        ROWNUM ELEMENT
             1 C:
             2 USERS
             3 marypoppins
             4 Docs
             5 Specification
    SQL>

  • How to get the value of String in integer type

    how to get the value of String in integer

    {color:#0000ff}http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
    http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#valueOf(java.lang.String){color}

  • Replacing a part of a String with a new String

    Hi everybody,
    is there a option or a method to replace a part of a String with a String???
    I only found the method "replace", but with this method I only can replace a char of the String. I don't need to replace only a char of a String, I have to replace a part of a String.
    e.g.:
    String str = "Hello you nice world!";
    str.replace("nice","wonderfull");   // this won't work, because I can't replace a String with the method "replace"
                                        // with this method I'm only able to replace charsDoes anyone know some method like I need???
    Thanks for your time on answering my question!!
    king regards
    IceCube-D

    do check java 1.4 api, I think there is a method in it, however for jdk1.3 you can use
    private static String replace(String str, String word,String word2) {
         if(str==null || word==null || word2 == null ||
               word.equals("") || word2.equals("") || str.equals("")) {
              return str;
         StringBuffer buff = new StringBuffer(str);
         int lastPosition = 0;
         while(lastPosition>-1) {
              int startIndex = str.indexOf(word,lastPosition);
              if(startIndex==-1) {
                   break;
              int len = word.length();
              buff.delete(startIndex,startIndex+len);
              char[] charArray = word2.toCharArray();
              buff.insert(startIndex,charArray);
              str = buff.toString();
              int len2 = startIndex+word2.length();
              lastPosition = str.indexOf(word,len2);
         return buff.toString();

  • Get name of query string parameter in JSTL

    Is there a way to get only the query string name in a URL in JSTL?
    i.e.
    http://www.mysite.com/mypage.jsp?name=value
    and return "name" as a string. I can't seem to find any documentation saying this is possible.

    If I am using c:out or any of the jstl-core tags I don't think the request.getXYZ functions will work in tandem. (Correct me if I'm wrong). It seems like they are called before the request is called (my terminology is awful, sorry). So by the time request.getParameterNames() is called, <c:out value = ""/> has already finished - hence I can't use the value from request.getParameterNames(). I guess I wasn't clear when I asked the question that that is what I wanted to do.
    This isn't exactly what I wanted but it will work:
    <c:forEach var='parameter' items='${paramValues}'>
    <c:out value='${parameter.key}'/>
    </c:forEach>
    at http://www.informit.com/articles/article.asp?p=30946&seqNum=7
    I answered my own question but thanks anyway.

  • How to get pixes of the String  ?

    In Stirng Object ,it'a provide String.length() to get the length of String ,But I tried to get the pixes of this Stirng . How can I do that?
    Best regards.

    Sorry,I would not describe this clearly.
    Exapmle we use below methed:
    public void paint( Graphics g )
    g.drawRect( 100,100 , 10, 10 )
    It's will paint a Rectangle with 10 "pixes" width and 10 "pixes" height on itself component .

  • Get the date as string

    Hi,
    How to get the date as string in j2me form which is declared as
    DateField datefield = new DateField("date ",DateField.DATE);
    String strDate=datefield.toString();
    System.out.println("Date "+strDate);
    But it display the value javax.microedition.lcdui.DateField@84aee8b.
    How to get the exact date value as string.

    Hi i used Another method ,but it works
    public String getDate(){
         Calendar calendar= Calendar.getInstance();
    int date=0,year=0,month=0;
    String strDate=null;
    date=calendar.get( java.util.Calendar.DATE);
    month=calendar.get( java.util.Calendar.MONTH)+1;
    year=calendar.get( java.util.Calendar.YEAR);
         strDate=date+"-"+month+"-"+year;
         if(date<10)
    strDate="0"+date+"-"+month+"-"+year;
    else
    strDate=date+"-"+month+"-"+year;
    return strDate;
    Please Tell me ,Is This correct or Not?
    By
    TechSivam

  • When you run Muse 2014 get an error unterminated string constant. Reinstalling does not help. System: Win8.1RU. Help!!!

    When you run Muse 2014 get an error unterminated string constant. Reinstalling does not help. System: Win8.1RU. Help!!!

    Is this occurring on launch? Can you post a screenshot? This isn't an error I recall being reported before.

  • I am having trouble printing  and am only getting part of the document which i have no margins set any help??

    i am having trouble printing  and am only getting part of the document  i have no margins set any help??

    What version of Pages?
    What Printer?
    If it is Pages '09, turn Comments off.
    Peter

Maybe you are looking for

  • Im trying to hook up my macbook pro with Lion os to new tv with Kanex mini displayport hdmi with no luck, any help?

    I'm trying to hook up my macbook pro to my new LG tv, I have the desktop screen on my tv (I was told I had to open a 2nd desktop and then drag my dvd screen into it, it still doesn't work.

  • How can i get an MP4 video file to work in iMovie 08'?

    I'm currently editing a wedding video i recorded on my Sony DV camcorder in iMovie 08' and want to splice a MP4 video file (from a mobile phone- make unknown) of the married couple on their first dance into the footage but can't How do i go about ach

  • NAM 5.1 How to create Application with port range from cli?

    Hello, I can create new Applicaion with port range from GUI, but I can not do it from CLI If I do it by CLI as a: nam# application nam# name mkst-cur-A nam# match udp 16001-16009 nam# exit then nam# show application app-tag 268435576 custom:120 (2684

  • HT1665 iphone stopped working with my ihome

    I have an Iphone 4s.  All of the sudden it stopped working with my ihome.  I have another iphone 4s and it still works with the ihome and I have an ipad and it works with the ihome so I am confident that the problem is not the ihome.  I have cleaned

  • Payment Summary for Web IC.

    Hi All, I have a requirement of displaying the payment summary of a BP to be displayed in a custom view!. which is a table view with fields like .. Payment Date Sales Document Type Sales Document No. Total Amount Payment Type- DD/CC details Payment S