SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Iowa, United States
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    More Literal fun! Adding text question

    Ok, I know how to add text to a literal with the
    myliteral.Text = "blah blah"

    but what if I have that and I want to add something before "blah blah"? what statement would I use?


    Does my question make sense?

  2. #2
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    do you mean setting html as text?

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Iowa, United States
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, sorry I wasn't clear.

    If the text value of the literal is

    "Blah Blah" and I want it to be
    "This is my Blah Blah", how do I do that?

    I know how to add text to the end, but how to add to the beginning.

  4. #4
    Chive On FFCus's Avatar
    Join Date
    Feb 2006
    Location
    Connecticut
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming myLiteral.Text is Blah Blah

    Code:
    myLiteral.Text = "This is my " & myLiteral.Text
    will output:

    This is my Blah Blah

  5. #5
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code Csharp:
    String.Format("This is my {0}", myLiteral.Text);

  6. #6
    Chive On FFCus's Avatar
    Join Date
    Feb 2006
    Location
    Connecticut
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ^ Better suggestion. I would imagine that's a more efficient use of resources.

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Iowa, United States
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginekitty View Post
    Code Csharp:
    String.Format("This is my {0}", myLiteral.Text);
    Awesome!! Thank you

    I had thought of doing it the way FFcus suggested but just somehow felt there must be a more elegant solution.

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Iowa, United States
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I found what I think is a better answer to my question, which is that the literal should be built using a string builder, then I can use the myStringBuilder.Insert to place the info at the beginning just before I write the stringbuilder to the literal.

    But the other solutions are probably great for other cases!

  9. #9
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    How long is the text in this literal?

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Iowa, United States
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginekitty View Post
    How long is the text in this literal?
    Hi, Sorry it took so long for me to respond. The text isn't horribly long. It is the product detail, so it is just several paragraphs of information pulled from a few different places and put together/formatted.

    A string might have been just as or more efficient.


Bookmarks

Posting Permissions

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