Repetitive white spaces in string

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Repetitive white spaces in string

    I want to prevent if visitor type more than 1 white space between two words.
    For example (I will use underscore "_" instead of white space " " here,
    because You cannot see repetitive white spaces, only in source):
    let's say, the string visitor will type in the input form field is:
    "macromedia___coldfusion_mx_____7"
    I want to replace all needless white spaces (or underscores here) and I want
    to get following string "macromedia_coldfusion_mx_7" - between two words I want
    to have only one white space

    have you any ideas?
    regards,
    d.acha

    d.acha Guest

  2. Similar Questions and Discussions

    1. How do I set string to null or all spaces
      :confused; I have a form I am submitting to itself. I want to the text area on the screen to stay until all error messages are cleared, so I stored...
    2. replace spaces with 0's in a string
      I have a string like this '00023MJKOP16598 09 00' I need to replace spaces in this string with zeros so that the spaces are gone. So it would...
    3. Scanned Graphics / Screen Shots / White Spaces
      I am using an IBM Windows XP / Microsoft Office 2003 with 504 RAM. I don't have CorelDRAW to copy my screen shots into. So therefore, I paste into...
    4. Adding white spaces
      Hi All, I have a file looking like (where \n is new line): blabla\n blablablablablabla\n blablablablablablablablablabla\n blabla\n but I...
    5. To count a number of lines in C++ or Java or ASCII files by exluding white spaces and comments
      Hi all, We have huge files in Java and C++ and I need to count the total number of lines in each of them by excluding white spaces (from the...
  3. #2

    Default Re: Repetitive extra blank spaces in string

    Use REReplace

    #reReplace(testString,"\s+"," ","All")#

    This a regular expression replace.
    The first param is the string that the extra white space is to be stripped
    from.
    The second param is a regular expression which you are looking to replace.
    The regular expression "\s+" means one or more white space characters.
    The third param is the string that you will be putting in place of the
    previous.
    The fourth param is optional, "All" indicates that you would like to replace
    all instances of the reg expression. The default for this param is "One" which
    will replace only the first occurance.

    The code below will allow you to see it in action.
    <cfset testString = "my cold fusion server">
    <pre>
    #testString#
    #reReplace(testString,"\s+"," ","All")#
    </pre>

    Best of Luck,
    Nancy

    nancy.debnam Guest

  4. #3

    Default Re: Repetitive extra blank spaces in string

    thanks nancy,

    that's that!

    Additionally, I have surrounded Your code with one Trim function and I have
    exactly what I have meant.
    Trim(reReplace(testString,"\s+"," ","All"))
    Bye the way, You have exactly typed what I have asked, but I need that Trim
    more.

    Thanks a lot
    dacha

    d.acha Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139