Post: [C#] Usefull stream functions
09-26-2011, 05:30 AM #1
Woof
...hmm
(adsbygoogle = window.adsbygoogle || []).push({});
Hello,
just thought I would share a little something with you.
Enzo

The first script will read and return the chars till it hits the argumented char.

script:
    
public char[] readTillChar(BinaryReader stream, int start, char tillchar)
{
int size = Convert.ToInt16(stream.BaseStream.Length);
char[] chars = { };
for (int i = start; i < size; i++)
{
char readchar = stream.ReadChar();
if (readchar == tillchar)
return chars;
else
chars[i] += readchar;
}
return chars;
}

How to use:
    
char[] chars = readTillChar(reader, 0, '\xFF'Winky Winky;


The next script returns the place of the argumented char via int.

Script:
    
public int getCharplace(BinaryReader stream, char find)
{
int size = Convert.ToInt16(stream.BaseStream.Length);
int counter = 0;
for (int i = 0; i < size; i++)
{
char readchar = stream.ReadChar();
if (readchar != find)
counter += 1;
else
return counter;
}
return counter;
}


How to use:
    
int where = getCharplace(reader,'\x00'Winky Winky;


So there you go, simple scripts I use very much in most of my data handling. =]
09-26-2011, 05:43 AM #2
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
Hello,
just thought I would share a little something with you.
Enzo

The first script will read and return the chars till it hits the argumented char.

script:
    
public char[] readTillChar(BinaryReader stream, int start, char tillchar)
{
int size = Convert.ToInt16(stream.BaseStream.Length);
char[] chars = { };
for (int i = start; i < size; i++)
{
char readchar = stream.ReadChar();
if (readchar == tillchar)
return chars;
else
chars[i] += readchar;
}
return chars;
}

How to use:
    
char[] chars = readTillChar(reader, 0, '\xFF'Winky Winky;


The next script returns the place of the argumented char via int.

Script:
    
public int getCharplace(BinaryReader stream, char find)
{
int size = Convert.ToInt16(stream.BaseStream.Length);
int counter = 0;
for (int i = 0; i < size; i++)
{
char readchar = stream.ReadChar();
if (readchar != find)
counter += 1;
else
return counter;
}
return counter;
}


How to use:
    
int where = getCharplace(reader,'\x00'Winky Winky;


So there you go, simple scripts I use very much in most of my data handling. =]


Interesting methods you have created there. No real criticisms, but when you say "I use very much in most of my data handling", what data handling are you doing where you need to read to a specific character, or find the position of a specific character in a stream? I mean, I see circumstances wherein you might do such a thing, however, I don't see how it would apply to most data handling.
Last edited by Epic? ; 09-26-2011 at 05:49 AM.

The following user thanked Epic? for this useful post:

Pichu
09-26-2011, 05:57 AM #3
Woof
...hmm
Originally posted by AsianInvasion View Post
Interesting methods you have created there. No real criticisms, but when you say "I use very much in most of my data handling", what data handling are you doing where you need to read to a specific character, or find the position of a specific character in a stream? I mean, I see circumstances wherein you might do such a thing, however, I don't see how it would apply to most data handling.

simple, lets say I want to read whats in the middle of x & z from xblahblahz
Get it? I normally use it with '\x00' and '\xFF' though.
09-26-2011, 07:07 AM #4
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
simple, lets say I want to read whats in the middle of x & z from xblahblahz
Get it? I normally use it with '\x00' and '\xFF' though.


But that's not really a practical situation is it? When would you ever want to read the value in the middle of x and z from xblahblahz? I'm just saying, do you have a real world example, in a program that you've created?
09-26-2011, 07:12 AM #5
Woof
...hmm
Originally posted by AsianInvasion View Post
But that's not really a practical situation is it? When would you ever want to read the value in the middle of x and z from xblahblahz? I'm just saying, do you have a real world example, in a program that you've created?

In my converter and my string modder.
Your argument is invalid.
09-26-2011, 06:59 PM #6
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
In my converter and my string modder.
Your argument is invalid.


So you used it in one tool then you made the assumption that it would be used "very much" and was applicable to "most most of my [BAdmaNgLiTcHa] data handling" (those are direct quotes)?
09-26-2011, 07:01 PM #7
Default Avatar
Brad
Guest
Originally posted by AsianInvasion View Post
So you used it in one tool then you made the assumption that it would be used "very much" and was applicable to "most most of my [BAdmaNgLiTcHa] data handling" (those are direct quotes)?


some people could find other uses for this or even use it in the own tool.
09-26-2011, 07:07 PM #8
Epic?
Awe-Inspiring
Originally posted by Dr.
some people could find other uses for this or even use it in the own tool.


As I stated in my very first post to this thread, there are perhaps a few obscure, but imaginable uses for such methods, I was just curious as to when this would be used in a majority of data handling, which is something that he stated.
09-26-2011, 07:09 PM #9
Woof
...hmm
Originally posted by AsianInvasion View Post
So you used it in one tool then you made the assumption that it would be used "very much" and was applicable to "most most of my [BAdmaNgLiTcHa] data handling" (those are direct quotes)?

I dont see what your aim is with trying to start an argument...
These scipts are used to get data via char[] and Int returns, if its not your kind of method then you dont need to get all stuck-up for no reason.
This is my method, if you like it or not I really do not care.
09-26-2011, 07:28 PM #10
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
I dont see what your aim is with trying to start an argument...
These scipts are used to get data via char[] and Int returns, if its not your kind of method then you dont need to get all stuck-up for no reason.
This is my method, if you like it or not I really do not care.


I never said I disliked your method, I even said, in my original post, that I do not have any complaints. Furthermore, I'm not trying to start an argument, or even cause any form of conflict.

I was just curious as to when you would use this in a majority of your data handling, and it seems my curiosity has uncovered something of a logical fallacy. But, I mean this as no offense towards you.

Copyright © 2025, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo