Skip navigation
Currently Being Moderated

Format string when get from database

Dec 12, 2013 4:03 AM

Tags: #flex #database #string #format

Hi all,

 

I have problem when display string which get form database.

Below is code sample for this problem :

var str:String = "Here is the first sentence. \n And here is the second sentence"

...

<s:Label   text="{str}"/>

 

 

=> the out put will :

    Here is the first sentence.

    And here is the second sentence

 

but when I get that string from SQL database, the out put is : Here is the first sentence. \n And here is the second sentence

it don't make new line when see "\n" character.

 

Hopefully, someone can help me.

 

Thanks and sorry for my bad english.

 
Replies
  • Currently Being Moderated
    Dec 12, 2013 9:06 AM   in reply to ndt.company

    Try changing s:Label/maxDisplayedLines or using mx:Text

     

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 12, 2013 9:05 PM   in reply to ndt.company

    Hi,

    if you have inserted this text in the database as is: "Here is the first sentence. \n And here is the second sentence" you will get exactly the same text in Flex- there is nothing surprising here.  Did you try inserting "Here is the first sentence.

    And here is the second sentence" ?

    If this will not work try: "Here is the first sentence." +  CHAR(13) + CHAR(10) + "And here is the second sentence".

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 13, 2013 9:54 AM   in reply to ndt.company

    It would be unusual for a string to have two characters '\' and 'n' to represent new lines when stored in databases or files.  The '\n' is usually converted beforehand by compilers or interpreters into the correct characters.  You might want to investigate how that is happening and change before it gets stored.

     

    But if you can't change it before it is stored, I believe you can use the following to convert it

    
    var fixedString:String = string.replace(/\\n/g, "\n");
    

     

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points