hi i wants to create an dll file for removing blankspaces in a given string..........
here iam writing the code but it was not working.....
please give me the correct code....
here iam using asp.net with vb.net

Namespace fillblank
    Public Class Class1
        Private Sub blankspces()
            Dim a
            Dim done
            a = " "
            Do Until done
                If InStr(1, a, "  ") = 0 Then
                    done = True
                Else
                    a = a.Replace("  ", String.Empty)
                End If
            Loop
            'a.Trim.Replace(" ", String.Empty)
        End Sub
    End Class
End Namespace

please help me

kvprajapati commented: Stop! -1

Dani AI

Generated

The original routine in the first post () has a few structural problems: it is a Private Sub (no input or return value), variables are declared without types, and the loop-control flag is never initialized — that makes the logic fragile and not reusable. was correct to point out built-in string methods for simple replacements, but repeatedly replacing double-spaces is brittle and will miss tabs, line breaks and other whitespace characters; ’s file-based VBScript is for a different scenario (file IO) and won’t help when a reusable DLL is required. A robust approach is to build a small Public class library with well-typed, public functions that either remove all whitespace or collapse consecutive whitespace to a single space.

Imports System.Text.RegularExpressions

Public Class StringCleaner
    Public Shared Function RemoveAllWhitespace(input As String) As String
        If String.IsNullOrEmpty(input) Then Return input
        Return Regex.Replace(input, "\s+", String.Empty)
    End Function

    Public Shared Function CollapseWhitespace(input As String) As String
        If String.IsNullOrEmpty(input) Then Return input
        Return Regex.Replace(input, "\s+", " ").Trim()
    End Function
End Class

Create a Class Library project in Visual Studio (target the same .NET version as the web app), add this class as Public, build to produce a DLL, then add a reference from the ASP.NET project and call the Shared methods from code-behind (for example: Dim cleaned = StringCleaner.CollapseWhitespace(rawInput)). Choose CollapseWhitespace when words must remain separated; choose RemoveAllWhitespace only when joining all tokens is intended. For very large files or streams, avoid building giant strings in memory — process line-by-line or use streaming APIs instead.

Recommended Answers

All 4 Replies

The built-in feature of .NET String class has methods to remove spaces in a given string. Why do you want to go for a custom method?

String str1 = "This is a string"
String str2  = str1.Replace(" ", String.Empty)

Here str2 will have the string value "Thisisastring".

The built-in feature of .NET String class has methods to remove spaces in a given string. Why do you want to go for a custom method?

String str1 = "This is a string"
String str2  = str1.Replace(" ", String.Empty)

Here str2 will have the string value "Thisisastring".

hi here i have to remove so many blank spaces that occurs within string in more than 10 forms....so i want to create an dll file ,by calling tha dll file the blank spaces withinn a string to be removed in every form........
so please give me the code for removing blank spaces for creartion of a dll file..........

kanuri1,

Please read the rules before posting again, in particular the 'keep it organized' one - Do not flood the forum by posting the same question more than once (ie in multiple forums). If you hit 10 infraction points your account gets an automatic ban, so it is worth obeying the rules if you want to continue to benefit from DaniWeb help.

Double threads:

1. http://www.daniweb.com/forums/thread261491.html
2. http://www.daniweb.com/forums/thread261509.html

Hi

I had same problem.You can use following code.It will help you.

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\scripts\test.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strLine = Trim(strLine) & vbCrLf
strText = strText & strLine
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("c:\scripts\test.txt", ForWriting)
objFile.Write strText
objFile.Close

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.