new #reReplace(original, "(0\s+0\s+0\s+)|(\s+0\s+0\s+0\s+0)", "", "all")#
old #reReplace(original, "(0\s0\s0\s)|(\s0\s0\s0\s0)", "", "all")#
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 7 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> trimming a string - Coldfusion - Getting Started

trimming a string - Coldfusion - Getting Started

I'm generating strings dynamically in my application, and they look something lie this: 0 0 0 435921014 0 0 0 0 What I want to do is trim off all the characters before the first '4' and after the second '4'. Would anyone be able to assist me with the syntax for that? Thank you......

  1. #1

    Default trimming a string

    I'm generating strings dynamically in my application, and they look something
    lie this:

    0 0 0 435921014 0 0 0 0

    What I want to do is trim off all the characters before the first '4' and
    after the second '4'. Would anyone be able to assist me with the syntax for
    that? Thank you...

    coolidge Guest

  2. #2

    Default Re: trimming a string

    <cfset Test = "0 0 0 435921014 0 0 0 0">
    <cfset GoodString = #Mid(Test, #findnocase("4",Test)#+1,
    #findnocase("4",Test,#findnocase("4",Test)#+1)# -
    #findnocase("4",Test)#-1)#>

    That should do it.

    allen@oysterweb.com Guest

  3. #3

    Default Re: trimming a string

    Use the mid() function:

    mid(string, start, count)

    Will you always have zeros at the beginning and end, or will they be varying
    digits with consistent spacing in between? That will determine how to trim the
    string.

    TurboMini Guest

  4. #4

    Default Re: trimming a string

    First, replace all the instances of "0 " (zero space) with ""
    Then replace all the instances of " 0" (space zero) with "".



    Originally posted by: coolidge
    I'm generating strings dynamically in my application, and they look something
    lie this:

    0 0 0 435921014 0 0 0 0

    What I want to do is trim off all the characters before the first '4' and
    after the second '4'. Would anyone be able to assist me with the syntax for
    that? Thank you...



    Dan Bracuk Guest

  5. #5

    Default Re: trimming a string

    As TurboMini mentioned, if the value will always be in the 4th position and
    each set of numbers will always be separated by a space, simply use the
    listGetAt() function with a space (chr(32) as the delimiter.

    <cfset yourValue = "0 0 0 435921014 0 0 0 0">
    <cfoutput>#ListGetAt(yourValue, 4, chr(32))#</cfoutput>

    mxstu Guest

  6. #6

    Default Re: trimming a string

    I would personally use regEx as it is cleaner:-

    <cfscript>
    original = "0 0 0 435921014 0 0 0 0";

    result = reReplace(original, "(0\s0\s0\s)|(\s0\s0\s0\s0)", "", "all");
    writeoutput("#wang#<br />#result#");
    </cfscript>

    Stressed_Simon Guest

  7. #7

    Default Re: trimming a string

    Just to be safe, you might want to structure the regular expresssion to search
    for multiple spaces between the zeros. Something like:

    <!--- more than one space in between first and second zero --->
    <cfset original = "0 0 0 435921014 0 0 0 0">
    <cfoutput>
    new #reReplace(original, "(0\s+0\s+0\s+)|(\s+0\s+0\s+0\s+0)", "", "all")#<br>
    old #reReplace(original, "(0\s0\s0\s)|(\s0\s0\s0\s0)", "", "all")#<br>

    mxstu Guest

Similar Threads

  1. trimming a string either side of a keyword
    By ceaseanddesist in forum Dreamweaver AppDev
    Replies: 4
    Last Post: May 31st, 08:16 AM
  2. trimming arcs/ellipses
    By Tonybob21 in forum Macromedia Freehand
    Replies: 3
    Last Post: July 10th, 05:18 PM
  3. Trimming Whitespace
    By Sean Levesley in forum Macromedia Director Basics
    Replies: 3
    Last Post: August 22nd, 10:17 PM
  4. Trimming Blank Spaces in String
    By Steve C. Orr, MCSD in forum ASP.NET General
    Replies: 1
    Last Post: August 9th, 12:46 AM
  5. trimming a variable.
    By mario c in forum ASP
    Replies: 2
    Last Post: July 21st, 11:37 PM

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
  •