×

Discussion Board

Results 1 to 2 of 2

Thread: string.replace

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    string.replace

    Hello, it is me again I"m making progress with my first app, but I got stuck on a simple issue, I'm sure it is just me being lame, but I seem not able to figure it out:

    I need to replace some characters in my string, for example "2" with "3", when I use it like this it works and it displays "test 3":

    Page {

    property string variable: "test 2"

    Text {
    text: variable.replace("2","3")
    }

    }

    But when I use it in function like this, it still shows "test 2"

    Page {

    function textreplace(tmptext) {


    tmptext.replace("2","3")
    return tmptext;

    }

    property string variable: "test 2"

    Text {
    text: textreplace(variable)
    }

    }

    I really don't know what is wrong? Thank you for every opinion.

  2. #2
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    Re: string.replace

    ha, so reply to myself again, I should delete this, but I will leave it here as a post of shame, shall anyone encounter similar problem. There are two problems. The replace is a javascript function and I forget to change the variable, so the function which work goes like this:

    function textreplace(tmptext) {
    tmptext = tmptext.replace(/2/gi,"3")
    return tmptext;
    }

    which will replace all ocurences (g) of the first character in the string, case insenstivie (i)

    Shame on me!

Similar Threads

  1. how to replace a string?
    By kumar1234567 in forum Mobile Java General
    Replies: 4
    Last Post: 2011-06-08, 11:26
  2. How to replace a sub-string by another in a descriptor
    By giang1194 in forum Symbian C++
    Replies: 6
    Last Post: 2011-03-24, 18:04
  3. Find and Replace a string in HBufc
    By prathibha83 in forum Symbian C++
    Replies: 8
    Last Post: 2010-09-15, 11:33
  4. find and replace string
    By kuddy_abc in forum Symbian C++
    Replies: 1
    Last Post: 2010-05-30, 08:42
  5. String search and replace
    By Zilppuri in forum Symbian C++
    Replies: 4
    Last Post: 2009-05-08, 19:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •