2012-08-06 38 views
1

我在水晶報告中工作,需要格式化電話號碼字段。我處理的數據在一定程度上搞砸了,並有一些數字格式正確無誤Crystal Reports電話號碼

(111)111-1111

和一些1111111111

我想寫這個公式,將刪除括號並重新格式化字符串。這裏就是我有這麼遠,不知道爲什麼這是不行的

StringVar phone = Replace({AssessorTrainingReport;1.Phone1},"(",""); 
phone := Replace({AssessorTrainingReport;1.Phone1},")",""); 
Picture (CStr (phone), "(xxx) xxx-xxxx"); 
+0

預期產量是多少?你想將第一個字符串格式化爲第二個或其他方式? – 2012-08-06 19:48:27

回答

2

第二替代調用應該從第一替代呼叫的STRINGVAR結果操作...

phone := Replace(phone,")",""); 

也,你需要刪除-嗎?

+0

我試圖做到這一點,實際上也沒有出現給我。我結束了我在我的存儲過程中拉動的字段上使用sql替換,並修復它。 替換(替換(cj.Phone1,' - ',''),'(',''),')','')Phone – clestbest 2012-08-06 20:26:14

0

如果你的號碼可以「搞砸」,那麼你可能要考慮消毒整個字符串(也爲那些好奇如何在CR做到這一點):

local stringvar phonenum := {table.phone_field}; 
local stringvar out := ""; 
local numbervar i; 
for i:=1 to length(phonenum) do 
    (
    if isnumeric(phonenum[i]) then //iterate over the characters in the string... 
     out:=out + phonenum[i]; //...and toss out those which are non-numeric 
); 

if length(out)<&gt10 then "Handle the error condition" else picture(out,"(xxx) xxx-xxxx")
0

創建一個自定義函數來「補充'替換()函數:

// ---------------------------------------------------------------------- 
// ReplaceEx() 
// Author:  Craig Buchanan 
// Purpose:  Support an array of find tokens 
// Parameters: text - the string being searched 
//    find - an array of characters to be found 
//    replacement - value to substitute 
// ---------------------------------------------------------------------- 
Function (Stringvar text, Stringvar Array find, Stringvar replacement) 

    local numbervar i; 

    For i:=1 To Ubound(find) do (

     text:=Replace(text, find[i], replacement) 

    ); 

    text; 

使用自定義函數在一個公式字段:

// returns {612) 555-1212 
Picture(ReplaceEx("612-555-1212", ["(",")","-"], ""), "(xxx) xxx-xxxx") 
1

//試試這個,在這種情況下它可以讓你替換任何你需要的東西。

StringVar phone:= {yourTable.field}; 
    phone:= Replace(phone,"(","*"); 
    mid(phone, 1); 
    replace(mid(phone, 1),")", "* "); 
0

嘗試......

右鍵點擊電話號碼字段,然後選擇格式字段 從格式字段中選擇Common選項卡。在顯示STRING CLICK X-2 BOX THEN WITE FORMULA - > PICTURE({YOURTABLE.FIELD),「(XXX)XXX-XXXX」)

希望這幫助!

+4

不需要SHOUT。偶爾嘗試使用小寫字母。 – 2014-12-01 21:25:58