LoginSignup
0
1

More than 5 years have passed since last update.

C++ Builder XE4 > クリップボードの文字列中の"/"を"/"に変換するツール v0.1 - v0.3

Last updated at Posted at 2018-08-08
動作環境
C++ Builder XE4
秀丸エディタ Version 8.79

処理概要

  • Clipboard中の文字列を半角"/"から全角"/"へ変換する

用途

はてなダイアリーの記事でタイトルに"/"を含む記事をesa.ioへ移行するとき、esa.ioでは"/"をカテゴリと認識してしまう (2018年8月8日現在)。

カテゴリとして認識されないために"/"を別の文字(例:全角"/")などに変換する場合、秀丸エディタ上では変換先の文字列を"/"と用意した上で、「ペーストから変換、コピーの処理」の過程でショートカットキー6回の入力になる。

本ツールを使うことにより、1回(ボタン押下)のみと作業を省略できる。

code v0.1

Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE で管理されるコンポーネント
    TMemo *Memo1;
    TButton *B_convert;
    TLabel *Label1;
    void __fastcall B_convertClick(TObject *Sender);
private:    // ユーザー宣言
public:     // ユーザー宣言
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------

/*
v0.1 2018/08/08
    - クリップボードの文字列中の半角"/"を全角"/"に変換する
*/


__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_convertClick(TObject *Sender)
{
    Memo1->Lines->Clear();

    // from Clipboard
    Memo1->PasteFromClipboard();

    // repalce string
    String instr = Memo1->Lines->Strings[0];
    String wrkstr = StringReplace(instr, L"/", L"/", TReplaceFlags()<<rfReplaceAll);

    // to Clipboard
    Memo1->Lines->Clear();
    Memo1->Lines->Add(wrkstr);
    Memo1->SelectAll();
    Memo1->CopyToClipboard();

}
//---------------------------------------------------------------------------

使用例

  1. 本ツール ('180808_slashToDoubleByte')を起動しておく
  2. コピー元文字列をクリップボードに送る (Ctrl+c)
  3. 本ツールのConvertボタンを押す
    • > クリップボードに変換済み文字列が入る
  4. クリップボードの文字列を任意の場所で使う

以下、Convertボタン押下後の様子 (元の文字列はA/B/C/D)。
qiita.png

不具合

  • 2018/08/10 とある文字列で変換後に文字列が切れる症状が見られた
    • code v0.2にて対応
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789D123456789C123456789B123456789A1234567890123456789012345678901234567890

95文字目まで切れた。
TMemoの画面表示サイズと一致するのが偶然だろうか。

code v0.2

v0.1の不具合に対処。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------

/*
v0.2 2018/08/10
    - fix bug > 長い文字列において文字列が途中までになる症状が見られた
v0.1 2018/08/08
    - クリップボードの文字列中の半角"/"を全角"/"に変換する
*/


__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_convertClick(TObject *Sender)
{
    Memo1->Lines->Clear();

    // from Clipboard
    Memo1->PasteFromClipboard();

    // repalce string
    String instr = Memo1->Lines->Strings[0];

    for(int idx=1; idx < Memo1->Lines->Count; idx++) {
        instr += Memo1->Lines->Strings[idx];
    }

    String wrkstr = StringReplace(instr, L"/", L"/", TReplaceFlags()<<rfReplaceAll);

    // to Clipboard
    Memo1->Lines->Clear();
    Memo1->Lines->Add(wrkstr);
    Memo1->SelectAll();
    Memo1->CopyToClipboard();

}
//---------------------------------------------------------------------------

code v0.3

v0.2をよりシンプルにした (Strings[]使用の代わりにText使用)。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------

/*
v0.3 2018/08/10
    - refactor > use Text instead of Strings[0] for Memo1->Lines
v0.2 2018/08/10
    - fix bug > 長い文字列において文字列が途中までになる症状が見られた
v0.1 2018/08/08
    - クリップボードの文字列中の半角"/"を全角"/"に変換する
*/


__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_convertClick(TObject *Sender)
{
    Memo1->Lines->Clear();

    // from Clipboard
    Memo1->PasteFromClipboard();

    // repalce string
    String instr = Memo1->Lines->Text;

    String wrkstr = StringReplace(instr, L"/", L"/", TReplaceFlags()<<rfReplaceAll);

    // to Clipboard
    Memo1->Lines->Clear();
    Memo1->Lines->Add(wrkstr);
    Memo1->SelectAll();
    Memo1->CopyToClipboard();

}
//---------------------------------------------------------------------------
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1