Mid function problem when "<" character is superceded by a letter

Posted on 2007-07-19
Last Modified: 2013-12-24
Coldfusion: I'm getting bizarre behaviour with the Mid function which uses strings which include the "<" character. When the "<" is superceded by a NUMBER the function works as expected, however when it is superceded by a LETTER it cuts short the result. Take a look a the code below and the output i receive. I will award points to whoever can explain why the last example (with the letter superceding the "<") give the result that it gives:

#Mid("123456789", 2, 9)#<br>
#Mid("1234<56789", 2, 9)#<br>
#Mid("1234<abcde", 2, 9)#<br>

results in:


many thanks!
Question by:paddycobbett
    LVL 24

    Assisted Solution

    Is it possible that it is thinking that the <a is the beginning of an html tag?
    LVL 1

    Author Comment

    It is true that the string i intend to substring is html, but i wouldn't have thought that the Mid function recognises that, i would have thought it just treats is as raw text right? or not? Even if i replace the a with a z such as:

    #Mid("1234<zbcde", 2, 9)#

    i get the same result. Any thoughts? and thanks for the response =)

    B.T.W there are no problems with the opposite ">" tag
    LVL 12

    Accepted Solution

    mankowitz is correct that it (the browser) thinks you're trying to use an html tag. If you view the source, you'll see that the remaining characters are present in the source code, they just don't appear on the page. Two options to solve this would include:
    #HTMLCodeFormat(Mid("1234<abcde", 2, 9))#<br>


    #Replace(Mid("1234<abcde", 2, 9),'<','&lt;')#<br>
    LVL 1

    Author Comment

    You're quite right both of you, hadn't occured to me that it was the browser's ill doing. Thanks guys!

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now