Thread Rating:
  • 488 Vote(s) - 2.85 Average
  • 1
  • 2
  • 3
  • 4
  • 5
int型→string型のキャストについて
08-27-2013, 06:13 PM,
#7
RE: int型→string型のキャストについて

int 等の数値型以外でも、BigDecimal なども文字列に変換したいことは多いです。
こんなコードを考えてみましたが、DateTime の文字列化のロジックが貧相。

Code:
{import * from COM.CURL.ORB.TYPE}
{import * from CURL.LANGUAGE.REFLECTION}

{define-proc public {get-String c:any}:#String
    let str:#String = null

    {if c isa DateTime then
        set str = (c asa DateTime).info.locale-full
    else
        {type-switch {type-of c}
         case num:NumericType do
            set str = c & ""
         else
            {for m in {({type-of c} asa ClassType).get-members
                          filter = ClassMember.method-filter
                      }
             do
                {switch m.name
                 case  "to-String", "get-text" do
                    set str = {(m asa Method).invoke c} asa #String
                    {break}

                }
            }
        }
    }
    {return str}
}

{CommandButton
    label = "オブジェクトを文字列にする",
    {on Action do
        {popup-message
            {VBox
                {get-String 6 asa int},
                {get-String 6.7 asa double},
                {get-String 'a' asa char},
                {get-String false asa bool},
                {get-String "String"},
                {get-String {DateTime}},
                {get-String {Frame  "Frame内の文字" }},
                {get-String {CTimestamp.value-of "2013-01-01 10:10:10" }},
                {get-String {BigDecimal.from-String "2013" }}

            }
        }
    }
}


Messages In This Thread
RE: int型→string型のキャストについて - by umemura - 08-27-2013, 06:13 PM
Forum Jump:


Users browsing this thread:
2 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('203')