ご質問の文字列は
AAA, AAB, AAC‥‥
といったイメージでしょうか。
であれば、Windows限定になりますが、下記のVBScriptで実現できます。
拡張子 vbs で保存(例:hogehoge.vbs)し、実行してみてください。
結果を出力するファイル名を Fname に、文字数は Col(ここでは3文字)に、並べる文字種は Table に指定します。Table には小文字や数字を順番に記述すれば、その順番通りに文字列を生成します。
Option Explicit const Fname = "hogehoge.txt" '出力ファイル名 const Col = 3 '出力桁数 const Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" '対象文字種 '------文字列作成のための再帰関数 Function addchar(str, cnt) Dim i, c If cnt <= Col Then For i = 1 to Len(Table) c = mid(Table, i, 1) addchar = addchar(str & c, cnt + 1) Next Else outfile.Write(str & chr(13)) End If End Function '--------メイン・プログラム Dim str, fs, outfile Set fs = WScript.CreateObject("Scripting.FileSystemObject") If Err.Number = 0 Then Set outfile = fs.OpenTextFile(Fname, 2, True) End If str = "" str = addchar(str, 1) outfile.Close Set fs = Nothing Set outfile = Nothing WScript.Echo Fname & " : 出力完了!"
#1で回答したプログラムは、改行処理が間違っていました。ごめんなさい。
以下に差し替えていただければ、メモ帳で開いたときに縦に並ぶと思います。
Option Explicit const Fname = "hogehoge.txt" '出力ファイル名 const Col = 3 '出力桁数 const Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" '対象文字種 '------文字列作成のための再帰関数 Function addchar(str, cnt) Dim i, c If cnt <= Col Then For i = 1 to Len(Table) c = mid(Table, i, 1) addchar = addchar(str & c, cnt + 1) Next Else outfile.Write(str & chr(13) & chr(10)) End If End Function '--------メイン・プログラム Dim str, fs, outfile Set fs = WScript.CreateObject("Scripting.FileSystemObject") If Err.Number = 0 Then Set outfile = fs.OpenTextFile(Fname, 2, True) End If str = "" str = addchar(str, 1) outfile.Close Set fs = Nothing Set outfile = Nothing WScript.Echo Fname & " : 出力完了!"
※設定された回答回数の上限になりました。さらにフォローが必要でしたら、コメント欄を開けていただくか、回答回数を増やしてください。
回答者 | 回答 | 受取 | ベストアンサー | 回答時間 | |
---|---|---|---|---|---|
1 | Gay_Yahng | 724回 | 660回 | 26回 | 2008-11-17 11:05:43 |
あ、これです。
これを3桁の時、”aaaaabaacaad・・・”ではなく
aaa
aab
aac
aad
のように縦に出力したのですが・・
できますか?