Thread match anhand von unicode control code (10 answers)
Opened by miwieg at 2018-01-14 13:05

rosti
 2018-01-14 18:55
#187919 #187919
User since
2011-03-19
3211 Artikel
BenutzerIn
[Homepage]
user image
Wenns bei Dir nicht matcht, ist das Zeichen nicht in der Datei. Code zum Testen untenstehend, der funktioniert. Guck mal in die Datei in hex-Ansicht, die Bytefolge ist E2 98 BA

http://rolfrost.de/ucd.html?gui=1;checkout=263A


Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;
use warnings;
use IO::File;
use Encode;

my $smiley = pack "U", 0x263a; 
    # Zeichen
my $bin = Encode::encode('UTF-8', $smiley);
    # binary f. Zeichen
my $file = 'd:/tmp/emos';

# Datei zum Testen anlegen
#writefile($file, $bin);

# testen ob Zeichen in Datei
# Vergleiche Zeichen
my $fh = IO::File->new;
$fh->open($file, "<:utf8") or die $!;
while( my $line = <$fh> ){
    chomp $line;
    
    # Ausgabe aller Codepoints
    print "@{[unpack 'U*', $line]}\n";
    
    print "Hier wird gelächelt!\n"
        if $line =~ /$smiley/;
}

# Schreibe Bytes in Datei
sub writefile{
    my $file = shift;
    my $s = shift;
    my $fh = IO::File->new;
    $fh->open($file, O_CREAT|O_TRUNC|O_RDWR|O_BINARY) or die $!;
    $fh->print("Bitte lächeln und zwar so: $s");
    $fh->close;
}

View full thread match anhand von unicode control code