Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the best way to remove white space after a certain character in a string?
    primarykey
    data
    text
    <p>I'm trying to build a list that will be used as the in clause of a select statement. The requirement is to have the user enter a comma separated list of descriptions. Each description can contain spaces so I can't remove the spaces before splitting by comma to add the single quotes around each description. I want to remove all white space after a single quote since no description will start with a space. What's the best way to do this in VB.NET? Regular expression or a string function? Here's what I have so far.:</p> <pre><code>Partial Class Test Inherits System.Web.UI.Page Protected Sub cmdGetParts_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdGetParts.Click Dim sDescriptionList As String = "" BuildList(sDescriptionList) RemoveSpacesFromList(sDescriptionList) FillGrid(sDescriptionList) End Sub 'Build descriptions List based on txtDescriptionList.Text Private Sub BuildList(ByRef sDescriptionList As String) Dim sDescriptionArray As String() sDescriptionArray = txtDescriptionList.Text.Trim.Split(","c) Dim iStringCount As Integer = 0 For Each description In sDescriptionArray If iStringCount &gt; 0 Then sDescriptionList = sDescriptionList &amp; "," End If sDescriptionList = sDescriptionList &amp; "'" &amp; description &amp; "'" iStringCount = iStringCount + 1 Next End Sub **'This procedure removes unwanted spaces from description list Private Sub RemoveSpacesFromList(ByRef sList As String) sList = sList.Replace("' ", "'") End Sub** 'This procedure fills the grid with data for descriptions passed in Private Sub FillGrid(ByVal sDescriptionList As String) Dim bo As New boPart Dim dtParts As Data.DataTable dtParts = bo.GetPartByDescriptionList(sDescriptionList) GridView1.DataSource = dtParts GridView1.DataBind() End Sub End Class </code></pre> <p><strong><em>Edited: After reviewing this code I think I may be able to just place description.Trim inside the For Each loop of the BuildList procedure.</em></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload