You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Crystal Reports Proper Case函数高级求助:地址8Th需修正为8th

Fixing Ordinal Suffix Capitalization in Crystal Reports Address Fields

Got it, let's tackle that frustrating address formatting issue! The built-in ProperCase function works perfectly for names, but it doesn't know to fix ordinal suffixes like "8Th" → "8th"—which definitely looks unprofessional for employee-facing docs. Here are two reliable solutions tailored to Crystal Reports:

1. Custom Formula for One-Off Use

This formula first applies proper case to your address, then scans for digits followed by miscapitalized ordinal suffixes (St/Nd/Rd/Th) and fixes them without breaking other words (like "Thomas" or "Third").

Create a new formula field and paste this code, replacing {YourTable.AddressField} with your actual address field:

Local StringVar formattedAddr := ProperCase({YourTable.AddressField});
Local NumberVar position := 1;

While position <= Length(formattedAddr) Do (
    // Check if current character is a digit
    If Mid(formattedAddr, position, 1) Like "#" Then (
        // Make sure we don't go out of bounds checking the suffix
        If position + 2 <= Length(formattedAddr) Then (
            Select Mid(formattedAddr, position + 1, 2)
                Case "St": formattedAddr := Replace(formattedAddr, Mid(formattedAddr, position + 1, 2), "st");
                Case "Nd": formattedAddr := Replace(formattedAddr, Mid(formattedAddr, position + 1, 2), "nd");
                Case "Rd": formattedAddr := Replace(formattedAddr, Mid(formattedAddr, position + 1, 2), "rd");
                Case "Th": formattedAddr := Replace(formattedAddr, Mid(formattedAddr, position + 1, 2), "th");
            ;
            // Skip ahead past the digit and suffix to avoid reprocessing
            position := position + 3;
        )
        Else (
            position := position + 1;
        )
    )
    Else (
        position := position + 1;
    )
);

formattedAddr

How it works:

  • Starts by standardizing the address to proper case (so "8TH AVE" becomes "8Th Ave")
  • Loops through each character to find digits, then checks the next two characters for common ordinal suffixes
  • Replaces miscapitalized suffixes with lowercase versions, leaving other words (like "Thornhill" or "St. Louis") untouched

2. Reusable Custom Function

If you need to apply this fix to multiple address fields across your report, turn the logic into a reusable custom function:

  1. Go to Field Explorer > Functions > Custom Functions > New
  2. Name it FixOrdinalProperCase
  3. Add a string parameter (e.g., inputString)
  4. Paste the formula code above, replacing ProperCase({YourTable.AddressField}) with ProperCase(inputString)
  5. Save the function

Now you can call it anywhere in your report like this:

FixOrdinalProperCase({YourTable.ShippingAddress})

Quick Notes:

  • This handles all common ordinal suffixes (1st, 2nd, 3rd, 4th-9th) and works with multi-digit numbers too (e.g., "101St" → "101st")
  • If you encounter edge cases (like suffixes separated by a space, though that's rare in addresses), you can adjust the loop logic to check for spaces after digits

内容的提问来源于stack exchange,提问作者Amanda Lampe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:40:02