Skip to main content
Inspiring
September 30, 2010
Answered

function to show spaces

  • September 30, 2010
  • 3 replies
  • 691 views

I have a variable value that is preceeded by spaces and I need to see them.  When I use <cfabort showerror"#var#"> it trims the value which does nothing for me.  Ive been thus far running a loop and converting each character to ASCII to find out whats all in there.... is there conversion or formatting function I can use to just show me the true var spaces and all??

TIA

-Aaron

    This topic has been closed for replies.
    Correct answer ilssac

    I would be surprised that <cfabort...> trims the white space (but I've never used it  with the showerror parameter.

    I would suspect it is more likely your browser that is not showing the whitespace, as that is the HTTP standard to 'trim' whitespace characters into a single one.

    IF this is the case, you should get more of what you want with a combonation of the <pre></pre> tags and|or something surounding the output like quotes or dashes.

    I'll often do something like this when I want to see if there is whitespace.

    <cfoutput>-=:#aVariable#:=-</cfoutput>

    3 replies

    BKBK
    Community Expert
    Community Expert
    September 30, 2010

    Test:<br>
    <cfset x0="x0">
    <cfset x1="& nbsp;x1">
    <cfset x2="& nbsp;& nbsp;x2">
    <cfset x3="& nbsp;& nbsp;& nbsp;x3">
    <cfoutput>#x0#<br>#x1#<br>#x2#<br>#x3#</cfoutput>

    The test suggests you could do something like

    <cfset myString = replaceNoCase(myString, " ", "& nbsp; ","all")>

    [Ignore the space between & and nbsp;]]

    Inspiring
    September 30, 2010

    You could replace the spaces with another character, such as ¿, which is not likely to appear in the variable.

    ilssac
    ilssacCorrect answer
    Inspiring
    September 30, 2010

    I would be surprised that <cfabort...> trims the white space (but I've never used it  with the showerror parameter.

    I would suspect it is more likely your browser that is not showing the whitespace, as that is the HTTP standard to 'trim' whitespace characters into a single one.

    IF this is the case, you should get more of what you want with a combonation of the <pre></pre> tags and|or something surounding the output like quotes or dashes.

    I'll often do something like this when I want to see if there is whitespace.

    <cfoutput>-=:#aVariable#:=-</cfoutput>

    Inspiring
    September 30, 2010

    To add to ilssac's comment.  You could replace whitespace with the HTML entity for a non-breaking space.

    Something like (code not tested):

    <cfset myValue="     I am a string    ">

    <!--- use regular expression to replace whitespace --->
    <cfset displayValue=ReReplace(myValue, "\s", " ", "ALL")>

    <cfoutput>===#displayValue#===</cfoutput>