text formatting...

i have a fairly simple perl issue, and i was wondering if you guys could help me:
i used code like this to format a textarea for html:
($text = $input{'text'});# =~ s/
/
/g;
the issue is, it still puts a line break before the
. however, if i were to change the code to (i know b/c i was writing to html and i checked the source code):
($text = $input{'text'});# =~ s/?/
/g;
if would replace every "?" with a
tag, as it should, without putting a line break. thus, it seems like the error is something unique to the
character. all i want is to turn my multiline string variable into 1 line with
tags interspersed somewhere in the middle. do you know of any way i could just delete those line breaks and make the variable a string with no line breaks? thank you for any help...

bolindilly@aol.com

ps: how do i access one character of a string variable?
is it: $mystr[7]?
thanks again

Comments

  • Hi,

    : i have a fairly simple perl issue, and i was wondering if you guys
    : could help me:
    : i used code like this to format a textarea for html:
    : ($text = $input{'text'});# =~ s/
    //g;
    : the issue is, it still puts a line break before the . however, if i
    : were to change the code to (i know b/c i was writing to html and i
    : checked the source code):
    : ($text = $input{'text'});# =~ s/?//g;
    : if would replace every "?" with a tag, as it should, without
    : putting a line break. thus, it seems like the error is something
    : unique to the
    character. all i want is to turn my multiline
    : string variable into 1 line with tags interspersed somewhere in the
    : middle. do you know of any way i could just delete those line breaks
    : and make the variable a string with no line breaks? thank you for
    : any help...

    Hmmm... Could it be anything to do with that some OSes use two characters for linebreaks.
    and
    . If you try stripping
    chars too it may work.

    $text = $input{'text'} =~ s/
    //g;

    On the other hand, I could me miles off.

    : ps: how do i access one character of a string variable?
    : is it: $mystr[7]?
    Use the substr function. $seventhchar = substr($mystr, 6, 1);
    Note 6 not 7 - as I remember it the first char is identified as 0 and not 1. There may be another way. :-)

    Jonathan



    -------------------------------------------
    Count your downloads:
    http://www.downloadcounter.com/
    And host your site:
    http://www.incrahost.com/
    Don't say I never give you anything... ;-)

  • : Hi,
    :
    : : i have a fairly simple perl issue, and i was wondering if you guys
    : : could help me:
    : : i used code like this to format a textarea for html:
    : : ($text = $input{'text'});# =~ s/
    //g;
    : : the issue is, it still puts a line break before the . however, if i
    : : were to change the code to (i know b/c i was writing to html and i
    : : checked the source code):
    : : ($text = $input{'text'});# =~ s/?//g;
    : : if would replace every "?" with a tag, as it should, without
    : : putting a line break. thus, it seems like the error is something
    : : unique to the
    character. all i want is to turn my multiline
    : : string variable into 1 line with tags interspersed somewhere in the
    : : middle. do you know of any way i could just delete those line breaks
    : : and make the variable a string with no line breaks? thank you for
    : : any help...
    :
    : Hmmm... Could it be anything to do with that some OSes use two characters for linebreaks.
    and
    . If you try stripping
    chars too it may work.
    :
    : $text = $input{'text'} =~ s/
    //g;
    :
    : On the other hand, I could me miles off.
    :

    thanks for the tip, but it didn't work. i tried checking for
    independently and removing it, but the line breaks didn't go away... anyone else have any ideas?

    : : ps: how do i access one character of a string variable?
    : : is it: $mystr[7]?
    : Use the substr function. $seventhchar = substr($mystr, 6, 1);
    : Note 6 not 7 - as I remember it the first char is identified as 0 and not 1. There may be another way. :-)
    :

    yeah, i knew about this, but i was wondering if there was a simpler way like there is in C++...

    thanks for any more help...
  • : : Hi,
    : :
    : : : i have a fairly simple perl issue, and i was wondering if you guys
    : : : could help me:
    : : : i used code like this to format a textarea for html:
    : : : ($text = $input{'text'});# =~ s/
    //g;
    : : : the issue is, it still puts a line break before the . however, if i
    : : : were to change the code to (i know b/c i was writing to html and i
    : : : checked the source code):
    : : : ($text = $input{'text'});# =~ s/?//g;
    : : : if would replace every "?" with a tag, as it should, without
    : : : putting a line break. thus, it seems like the error is something
    : : : unique to the
    character. all i want is to turn my multiline
    : : : string variable into 1 line with tags interspersed somewhere in the
    : : : middle. do you know of any way i could just delete those line breaks
    : : : and make the variable a string with no line breaks? thank you for
    : : : any help...

    Try escaping the '
    ' like this:
    s/\n/
    /g

    X
  • Maybe instead of
    s/
    //g;
    you should use
    s/[
    ]+//g;

    It probably won't help because I'm just learning regexes, but maybe you just overlooked that in your expertise :)

    : : : Hi,
    : : :
    : : : : i have a fairly simple perl issue, and i was wondering if you guys
    : : : : could help me:
    : : : : i used code like this to format a textarea for html:
    : : : : ($text = $input{'text'});# =~ s/
    //g;
    : : : : the issue is, it still puts a line break before the . however, if i
    : : : : were to change the code to (i know b/c i was writing to html and i
    : : : : checked the source code):
    : : : : ($text = $input{'text'});# =~ s/?//g;
    : : : : if would replace every "?" with a tag, as it should, without
    : : : : putting a line break. thus, it seems like the error is something
    : : : : unique to the
    character. all i want is to turn my multiline
    : : : : string variable into 1 line with tags interspersed somewhere in the
    : : : : middle. do you know of any way i could just delete those line breaks
    : : : : and make the variable a string with no line breaks? thank you for
    : : : : any help...
    :
    : Try escaping the '
    ' like this:
    : s/\n//g
    :
    : X
    :

  • actually, in response to all this, i forgot to write what i did. i solved it. i just wrote a loop that went through the string i had one character at a time and added the character on to a new string. if it found a line break, it added "
    " instead of the line break...

    it worked like a charm...

    : Maybe instead of
    : s/
    //g;
    : you should use
    : s/[
    ]+//g;
    :

  • PS. you can access each character in a string by splitting it by a blank delimeter into array first, like this,

    @str_array = split(//,$my_str);#there must be NO space between the two slashes

    and now you can access each character by calling $str_array[0], $str_array[1], ...

    hope that might help ^_^


    : i have a fairly simple perl issue, and i was wondering if you guys could help me:
    : i used code like this to format a textarea for html:
    : ($text = $input{'text'});# =~ s/
    //g;
    : the issue is, it still puts a line break before the . however, if i were to change the code to (i know b/c i was writing to html and i checked the source code):
    : ($text = $input{'text'});# =~ s/?//g;
    : if would replace every "?" with a tag, as it should, without putting a line break. thus, it seems like the error is something unique to the
    character. all i want is to turn my multiline string variable into 1 line with tags interspersed somewhere in the middle. do you know of any way i could just delete those line breaks and make the variable a string with no line breaks? thank you for any help...
    :
    : bolindilly@aol.com
    :
    : ps: how do i access one character of a string variable?
    : is it: $mystr[7]?
    : thanks again
    :

  • : PS. you can access each character in a string by splitting it by a blank delimeter into array first, like this,
    :
    : @str_array = split(//,$my_str);#there must be NO space between the two slashes
    :
    : and now you can access each character by calling $str_array[0], $str_array[1], ...
    :
    : hope that might help ^_^
    :

    Wow...sweet tip. :-)

    Jonathan

    -------------------------------------------
    Count your downloads:
    http://www.downloadcounter.com/
    And host your site:
    http://www.incrahost.com/
    Don't say I never give you anything... ;-)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories