• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find the last character in an aplhanumreic string

New Here ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

Hi guys first time poster long time hiding in the shadows, hopefully someone can help me

I have set of username stored and I need to find the last character before the number for example

abc123 I would want to find c
ab123 I would want to find b

any suggestions as to how I would do this?
Thanks in advance
TOPICS
Advanced techniques

Views

517

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , May 01, 2007 May 01, 2007
Here's one way:
<CFSET YourString = "abc123")>
<CFSET LastChar = "">
<CFSET Pos = 1>
<CFSET CharLen = Len(YourString)>
<CFLOOP from="1" to="#CharLen#" step="1">
<CFSET Char = right(left(YourString,Pos),1)>
<CFIF Not IsNumeric(Char)>
<CFSET LastChar = Char>
<CFSET Pos = Pos + 1>
<CFELSE>
<CFBREAK>
<CFIF>
</CFLOOP>

Votes

Translate

Translate
Contributor ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

Here's one way:
<CFSET YourString = "abc123")>
<CFSET LastChar = "">
<CFSET Pos = 1>
<CFSET CharLen = Len(YourString)>
<CFLOOP from="1" to="#CharLen#" step="1">
<CFSET Char = right(left(YourString,Pos),1)>
<CFIF Not IsNumeric(Char)>
<CFSET LastChar = Char>
<CFSET Pos = Pos + 1>
<CFELSE>
<CFBREAK>
<CFIF>
</CFLOOP>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

Here is another one,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

I would mark you both as correct if possible thanks for your time guys!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

This strikes me as easier...

<CFSET StringToSearch = "1112hjk45P667">

<CFSET NewString = #REReplaceNoCase(StringToSearch, "[^a-z]", "", "ALL")#>
<CFSET LastCharacter = #Right(Trim(NewString),1)#>

Last character in #StringToSearch# is #LastCharacter#

Note that it should return a 'P' based on my example string.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

Once again, we see that there are many ways to do the same thing. So when somebody says there is only 1 right way, smack em upside the head with a keyboard. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

Do we have to wait until they say there is only 1 right way???

Co-workers are like slinkys... not a lot of fun until you push them down the stairs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

> Co-workers are like slinkys... not a lot of fun until you push them down the stairs.

SNORT!

Hahahahahahaha.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 01, 2007 May 01, 2007

Copy link to clipboard

Copied

LATEST
I prefer the shove off the roof in some cases. But swirlies are always good for a laugh.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation