半角、全角文字変換

 投稿者:しばっち  投稿日:2009年 5月10日(日)15時38分13秒
  半角、全角文字変換


PRINT CDBL$("ABCDABC123") !'半角を全角文字へ
PRINT CSNG$("あいうABCDE1231234") !'全角を半角文字へ
FOR I=1 TO 100
   PRINT CDBL$(STR$(I) & ":" & NUM2ROMAN$(I))
NEXT I
END

EXTERNAL  FUNCTION CDBL$(X$)
FOR I=1 TO LEN(X$)
   LET  F$=MID$(X$,I,1)
   RESTORE
   DO
      READ A$,AA$
   LOOP UNTIL A$="" OR F$=A$
   IF A$="" THEN LET  AA$=F$
   LET  L$=L$ & AA$
NEXT I
LET  CDBL$=L$
DATA A,A,B,B,C,C,D,D,E,E,F,F,G,G,H,H,I,I,J,J,K,K,L,L,M,M,N,N,O,O,P,P,Q,Q,R,R,S,S,T,T,U,U,V,V,W,W,X,X,Y,Y,Z,Z
DATA a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h,i,i,j,j,k,k,l,l,m,m,n,n,o,o,p,p,q,q,r,r,s,s,t,t,u,u,v,v,w,w,x,x,y,y,z,z
DATA 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9
DATA "!",!,"#",#,"$",$,"%",%,"&",&,"'",’,"(",(,")",),"=",=,"~",~,"+",+,"-",-,"*",*,"/",/,".",.,"<",<,">",>,"?",?,";",;,":",:,"@",@,"\",¥
DATA " "," "
DATA "",""
END FUNCTION

EXTERNAL  FUNCTION CSNG$(X$)
FOR I=1 TO LEN(X$)
   LET  F$=MID$(X$,I,1)
   RESTORE
   DO
      READ A$,AA$
   LOOP UNTIL A$="" OR F$=AA$
   IF A$="" THEN LET  A$=F$
   LET  L$=L$ & A$
NEXT I
LET  CSNG$=L$
DATA A,A,B,B,C,C,D,D,E,E,F,F,G,G,H,H,I,I,J,J,K,K,L,L,M,M,N,N,O,O,P,P,Q,Q,R,R,S,S,T,T,U,U,V,V,W,W,X,X,Y,Y,Z,Z
DATA a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h,i,i,j,j,k,k,l,l,m,m,n,n,o,o,p,p,q,q,r,r,s,s,t,t,u,u,v,v,w,w,x,x,y,y,z,z
DATA 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9
DATA "!",!,"#",#,"$",$,"%",%,"&",&,"'",’,"(",(,")",),"=",=,"~",~,"+",+,"-",-,"*",*,"/",/,".",.,"<",<,">",>,"?",?,";",;,":",:,"@",@,"\",¥
DATA " "," "
DATA "",""
END FUNCTION

EXTERNAL  FUNCTION NUM2ROMAN$(X) !'(アラビア)数字 to ローマ数字(1以上4000未満)
LET R$=""
IF X < 4000 AND X > 0 THEN
   OPTION BASE 0
   DIM T$(4,9)
   FOR I=1 TO 3
      FOR J=1 TO 9
         READ T$(I,J)
      NEXT J
   NEXT I
   DATA I,II,III,IV,V,VI,VII,VIII,IX
   DATA X,XX,XXX,XL,L,LX,LXX,LXXX,XC
   DATA C,CC,CCC,CD,D,DC,DCC,DCCC,CM
   FOR J=1 TO 3
      READ T$(4,J)
   NEXT J
   DATA M,MM,MMM,MMMM
   LET A$=LTRIM$(STR$(INT(X)))
   FOR I=LEN(A$) TO 1 STEP -1
      LET J=VAL(MID$(A$,LEN(A$)-I+1,1))
      LET R$=R$ & T$(I,J)
   NEXT I
END IF
LET NUM2ROMAN$=R$
END FUNCTION
 

戻る