2012-10-29 63 views

回答

2

我在顯示字符串中設置了一些代碼,以基本上白名單字符。大約如下:

stringvar input := {report.field}; 
stringvar output := ''; 
numbervar i; 

input := Trim(input); 

for i := 1 to Length(input) Step 1 do 

    // 0-9 is 48-57 
    // A-Z is 65-90 
    // a-z is 97-122 

    if (input[i] in [Chr(48),Chr(49),Chr(50),Chr(51),Chr(52),Chr(53),Chr(54),Chr(55),Chr(56),Chr(57),Chr(65),Chr(66),Chr(67),Chr(68),Chr(69),Chr(70),Chr(71),Chr(72),Chr(73),Chr(74),Chr(75),Chr(76),Chr(77),Chr(78),Chr(79),Chr(80),Chr(81),Chr(82),Chr(83),Chr(84),Chr(85),Chr(86),Chr(87),Chr(88),Chr(89),Chr(90),Chr(97),Chr(98),Chr(99),Chr(100),Chr(101),Chr(102),Chr(103),Chr(104),Chr(105),Chr(106),Chr(107),Chr(108),Chr(109),Chr(110),Chr(111),Chr(112),Chr(113),Chr(114),Chr(115),Chr(116),Chr(117),Chr(118),Chr(119),Chr(120),Chr(121),Chr(122)]) 
    then output := output + input[i]; 

output 

如果任何人有一個更清潔/更短的方式做到這一點,請分享!

0

創建一個SQL表達式:

//{%MY_FIELD} 
// Oracle syntax 
REGEXP_REPLACE(TABLE.FIELD, '[^0-9]', '') 
+0

Gotcha - 我應該澄清,我正在尋找在報告中做到這一點,而不是SQL。在這種情況下,我的響應中的代碼位於顯示字符串公式中。據我可以告訴Crystal沒有一個本地函數來執行正則表達式查找和替換。 – Chords

+0

SQL Expression會將REGEX傳遞到數據庫以便在查詢的'SELECT'子句中處理 - 非常乾淨。 您可以在其他字段的顯示字符串公式中引用SQL表達式。 你是對的:CR沒有原生的正則表達式支持。你可以使用http://sourceforge.net/projects/cruflregex。 – craig

相關問題