Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How do you remove muiltiple characters in a string [vb.net]
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Feb 18, 2009 4:58 pm    Post subject: How do you remove muiltiple characters in a string [vb.net] Reply with quote

I am making a file parser and I need to know how to remove muiltiple characters. So pretend I have a string that contains
Code:

a
a
b
b
b


I want to make it so it only has only one 'a' and one 'b' so it will look like this
Code:

a
b


Does anyone know how to do this?

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Wed Feb 18, 2009 5:53 pm    Post subject: Reply with quote

I don't know how to do it in VB.net, but I know how to do it in C++.

Code:

DWORD FilterString(PTSTR szStringToFilter, PTSTR szReturnBuffer, SIZE_T dwStringSize, SIZE_T dwBufferSize)
/*
    This routine filters a string so that only 1 of each character is kept. The return value is the number of characters copied to the buffer.
*/
{
   unsigned int i, j, k;

   k = 0;
   ZeroMemory(szReturnBuffer, dwBufferSize);
   for (i = 0; i < dwStringSize; i++)
   {
      for (j = 0; j < k; j++)
      {
         if (szStringToFilter[i] == szReturnBuffer[j])
         {
            break;
         }
      }
      if (j == (dwBufferSize - 1))
      {
         szReturnBuffer[k] = szStringToFilter[i];
         k++;
      }
   }
   return k;
}
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Feb 18, 2009 6:01 pm    Post subject: Reply with quote

Thanks anyways.

Also how can you remove all lines that don't have special characters?

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Wed Feb 18, 2009 8:23 pm    Post subject: Reply with quote

jorg hi you could just use strcspn to find occurances of charecters

this is a representation of the logic.. easily tranferable to VB or w/e

firstchar = w/e it takes to get first char in VB.net
size_t i = strcspn(string+1,firstchar);
if(i)
*(char*)string+i = 0x00;
repeat strcspn(string+i,firstchar) to find next occurance and zero it out
do this till i = strlen(string+i)

hopefully this helps..

regards BanMe

_________________
don't +rep me..i do not wish to have "status" or "recognition" from you or anyone.. thank you.
Back to top
View user's profile Send private message MSN Messenger
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Feb 18, 2009 8:26 pm    Post subject: Reply with quote

BanMe wrote:
jorg hi you could just use strcspn to find occurances of charecters

this is a representation of the logic.. easily tranferable to VB or w/e

firstchar = w/e it takes to get first char in VB.net
size_t i = strcspn(string+1,firstchar);
if(i)
*(char*)string+i = 0x00;
repeat strcspn(string+i,firstchar) to find next occurance and zero it out
do this till i = strlen(string+i)

hopefully this helps..

regards BanMe


Ahh I sort of get this.

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Feb 19, 2009 7:51 am    Post subject: Reply with quote

I tried to translate c# into vb.net using codechanger.com but I dont know if it failed
Code:
       
private void Form1_Load(object sender, EventArgs e)
{
    string message = StringBuilder("abcef", "abc".ToCharArray());
    MessageBox.Show(message);
}

private string StringBuilder(string input, char[] CharsToRemove)
{
    foreach (char c in CharsToRemove)
    {
       input = input.Replace(c.ToString(), "");
     }
  return input;
}

Code:
Private Sub Form1_Load(sender As Object, e As EventArgs)
   Dim message As String = StringBuilder("abcef", "abc".ToCharArray())
   MessageBox.Show(message)
End Sub

Private Function StringBuilder(input As String, CharsToRemove As Char()) As String
   For Each c As Char In CharsToRemove
      input = input.Replace(c.ToString(), "")
   Next
   Return input
End Function


'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Built and maintained by Todd Anglin and Telerik
'=======================================================

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Thu Feb 19, 2009 5:52 pm    Post subject: Reply with quote

It works but I want it to check the string for muiltiple characters and remove all of the muiltiple chars except for one of them so..
Code:
1
2
3
4
5
5
5


Will become
Code:
1
2
3
4
5

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Fri Feb 20, 2009 9:10 pm    Post subject: Reply with quote

Code:

//C#:
private void removeDuplicates(ref string s)
{
    for (int i = 0; i < s.Length; i++)
    {
        for (int j = 1; j < s.Length - i; j++)
        {
            if (s[i] == s[i+j]) //duplicate character; we need to remove it
                s = s.Remove(i+j, 1);
        }
    }
}


Code:

'VB:
Private Sub removeDuplicates(ByRef s As String)
    For i As Integer = 0 To s.Length - 1
        For j As Integer = 1 To s.Length - i - 1
            If s(i) = s(i + j) Then
                'duplicate character; we need to remove it
                s = s.Remove(i + j, 1)
            End If
        Next
    Next
End Sub


I suppose.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Fri Feb 20, 2009 9:16 pm    Post subject: Reply with quote

samuri25404 wrote:
Code:

//C#:
private void removeDuplicates(ref string s)
{
    for (int i = 0; i < s.Length; i++)
    {
        for (int j = 1; j < s.Length - i; j++)
        {
            if (s[i] == s[i+j]) //duplicate character; we need to remove it
                s = s.Remove(i+j, 1);
        }
    }
}


Code:

'VB:
Private Sub removeDuplicates(ByRef s As String)
    For i As Integer = 0 To s.Length - 1
        For j As Integer = 1 To s.Length - i - 1
            If s(i) = s(i + j) Then
                'duplicate character; we need to remove it
                s = s.Remove(i + j, 1)
            End If
        Next
    Next
End Sub


I suppose.


FINALLY!

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Fri Feb 20, 2009 10:18 pm    Post subject: Reply with quote

It's not very efficient, but it'll be fine for small strings.

Couldn't think of anything else off the top of my head.

Jorg hi wrote:

Thanks anyways.

Also how can you remove all lines that don't have special characters?


Define special characters?

Code:

//C#:
bool bGoodLine;
List<string> Lines = new List<string(streamReader.ReadToEnd().Split(Environment.NewLine)));
for (int i = 0; i < Lines.Count; i++)
{
    GoodLine = false;
    for (int j = 0; j < Lines[i].Length; j++)
    {
        if (!Char.IsAlpha(Lines[i][j]) && !Char.IsDigit(Lines[i][j]))
            bGoodLine = true;
    }

    if (!bGoodLine)
    {
        Lines.RemoveAt(i);
        i--;
    }
}

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sat Feb 21, 2009 8:45 am    Post subject: Reply with quote

Characters like
Code:

basically every character except for numbers, letters, and the period character.

Wait a sec, can you make it so it can remove same strings on lines so
I'm going to use vbcrlf as a line splitter.
Code:
general
orange
general
orange
pie


will be...

Code:
orange
general
pie


?

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Feb 21, 2009 10:06 am    Post subject: Reply with quote

Jorg hi wrote:
Characters like
Code:

basically every character except for numbers, letters, and the period character.

Wait a sec, can you make it so it can remove same strings on lines so
I'm going to use vbcrlf as a line splitter.
Code:
general
orange
general
orange
pie


will be...

Code:
orange
general
pie


?


First thing:
[I made some changes that should be used for the other code too; I was tired when I made it last night]

Code:

//C#:
//using System.IO;
//using System.Collections.Generic;
private string removeDuplicates(string Path)
{
    try
    {
        StreamReader sr = new StreamReader(Path);
        List<string> Text = sr.ReadToEnd().Replace("\r", String.Empty).Split("\n");
        for (int i = 0; i < Text.Count; i++)
        {
            for (int j = 1; j < s.Count- i; j++)
            {
                if (Text [i] == Text [i+j]) //duplicate string; we need to remove it
                {
                    s = s.RemoveAt(i+j);
                    j--;
                 }
            }
        }
    }
    catch (Exception e)
    { /*do something here*/ }
}


Code:

'VB:
'Imports System.IO
'Imports System.Collections.Generic
Private Function removeDuplicates(ByVal Path As String) As String
    Try
        Dim sr As New StreamReader(Path)
        Dim Text As List(Of String) = sr.ReadToEnd().Replace(vbCr, [String].Empty).Split(vbLf)
        For i As Integer = 0 To Text.Count - 1
            For j As Integer = 1 To s.Count - i - 1
                If Text(i) = Text(i + j) Then
                    'duplicate string; we need to remove it
                    s = s.RemoveAt(i + j)
                    j -= 1
                End If
            Next
        Next
    Catch e As Exception
        'do something here
    End Try
End Function


Second thing:

Code:

//C#:
bool bGoodLine;
List<string> Lines = new List<string>(streamReader.ReadToEnd().Replace("\r", String.Empty).Split("\n")));
for (int i = 0; i < Lines.Count; i++)
{
    GoodLine = false;
    for (int j = 0; j < Lines[i].Length; j++)
    {
        if (!Char.IsAlpha(Lines[i][j]) && !Char.IsDigit(Lines[i][j]) && Lines[i][j] != '.')
            bGoodLine = true;
    }

    if (!bGoodLine)
    {
        Lines.RemoveAt(i);
        i--;
    }
}


The converter thing didn't like that, so whatever.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sat Feb 21, 2009 2:03 pm    Post subject: Reply with quote

I'll have to find a way to convert this +rep.
_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sat Feb 21, 2009 3:06 pm    Post subject: Reply with quote

Being from a Perl background i tend to think a regular expression would suite your needs far easier then this method and provide alot more flexibility.. not knowing what C# or VB.net use for regular expression i googled it and found some pretty interest results..knowing that there called recipes helped greatly in finding this..

for C# ppl out there
http://en.csharp-online.net/CSharp_Regular_Expression_Recipes/


for the vb ppl out there..
http://www.devarticles.com/c/a/VB.Net/Regular-Expressions-in-.NET/1/

regards BanMe
Back to top
View user's profile Send private message MSN Messenger
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sat Feb 21, 2009 3:23 pm    Post subject: Reply with quote

BanMe wrote:
Being from a Perl background i tend to think a regular expression would suite your needs far easier then this method and provide alot more flexibility.. not knowing what C# or VB.net use for regular expression i googled it and found some pretty interest results..knowing that there called recipes helped greatly in finding this..

for C# ppl out there
http://en.csharp-online.net/CSharp_Regular_Expression_Recipes/


for the vb ppl out there..
http://www.devarticles.com/c/a/VB.Net/Regular-Expressions-in-.NET/1/

regards BanMe


ahh thanks.

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites