#!/usr/local/m17n_ruby/bin/ruby -Ks require 'nkf' s = "123あいう" p s.encoding #=> "sjis" p s.length #=> 6 p s #=> "123あいう" p s.reverse #=> "ういあ321" p s.encoding='latin1' #=> "latin1" p s.length #=> 9 p s #=> "123\202\240\202\242\202\244" s = NKF.nkf("-e", s) p s.encoding='euc-jp' #=> "euc-jp" p s.length #=> 6 p s #=> "123、「、、、ヲ"
Option Explicit Declare Function GetStdHandle Lib "kernel32" _ (ByVal nStdHandle As Long) As Long Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _ (ByVal hConsoleOutput As Long, _ lpBuffer As Any, _ ByVal nNumberOfCharsToWrite As Long, _ lpNumberOfCharsWritten As Long, _ lpReserved As Any) As Long Declare Function GetLastError Lib "kernel32" () As Long Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" _ (ByVal dwFlags As Long, _ lpSource As Any, _ ByVal dwMessageId As Long, _ ByVal dwLanguageId As Long, _ ByVal lpBuffer As String, _ ByVal nSize As Long, _ Arguments As Long) As Long Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000 Public Const STD_OUTPUT_HANDLE = -11& Public Const INVALID_HANDLE_VALUE = -1
Sub errdlg() Dim str$, rc& rc = GetLastError() str = Space(256) rc = FormatMessage( _ FORMAT_MESSAGE_FROM_SYSTEM, _ 0, rc, 0, str, LenB(str), 0) rc = MsgBox(str, vbOKOnly, "error") End Sub
Sub Main() Dim h&, str$, wrsz&, dummy, rc& h = GetStdHandle(STD_OUTPUT_HANDLE) If h = INVALID_HANDLE_VALUE Then errdlg End If str = "abcd" rc = WriteConsole(h, str, LenB(str), wrsz, dummy) If rc = 0 Then errdlg End If End Sub
p.0 = 2; p.1 = 3 n = 5; k = 2 do while k < 100000 i = 1 do while n // p.i <> 0 if n < p.i * p.i then do p.k = n k = k + 1 /* say n */ leave end i = i + 1 end n = n + 2 end