[C#]

Pagina: 1
Acties:
  • 32 views sinds 30-01-2008

  • monnick
  • Registratie: December 2005
  • Niet online
C#:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;

class StringBuilder
{
    Byte[] blob;
    int position;

    StringBuilder()
    {
        blob = new Byte[1000];
        position = 0;
    }

    // Splitst een string in een byte array.
    public void StoreString(string input)
    {
        for (int i = 0; i < input.Length; i++)
        {
            blob[position] = (byte)input[i];
            position++;
        }
    }

    // Voegt alle bytes samen zodat een string ontstaat.
    public void PrintString()
    {
        char[] C_output;
        string output;

        C_output = new char[1000];
        output = "";

        for (int i = 0; i < position; i++)
        {
            C_output[i] = (char)blob[i];
            output = output.Insert(output.Length, Convert.ToString(C_output[i]));
        }

        Console.WriteLine(output);
    }

    public static void Main()
    {
        StringBuilder app = new StringBuilder();
        app.StoreString("Hello World!");
        app.PrintString();

        Console.ReadKey();
    }
}


SHIT, wilde even iets uitproberen -> toen verongelijk op "verstuur bericht" geklikt. Dit topic kan dus weg. 8)7

[ Voor 5% gewijzigd door monnick op 25-09-2006 21:59 ]


  • Snake
  • Registratie: Juli 2005
  • Laatst online: 07-03-2024

Snake

Los Angeles, CA, USA

Je doet wel veel moeite om een string op te slaan he :P

Going for adventure, lots of sun and a convertible! | GMT-8


  • monnick
  • Registratie: December 2005
  • Niet online
Ja, ik moet toch wat doen om te oefenen met C#. :P

Verwijderd

Wat dacht je van het op deze manier te doen?

// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

En weer de andere kant uit:
// C# to convert a byte array to a string.
byte [] dBytes = ...
string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 13-02 21:26

Creepy

Tactical Espionage Splatterer

Oh well :)

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Dit topic is gesloten.