You must Sign In to post a response.
  • Category: .NET

    How to Remove the comma from last string in vb.net


    Are you looking for a way to Remove the comma from last string in vb.net ? then read this thread to know more about it



    insert into tableA(A,B,C,D,E,F) values(ram,sham,nitin,rahul,nilesh,)
    insert into tableA(A,B,C,D,E,F) values(am,ham,tin,hul,lesh,)
    and so much data like above
    i am getting this value in string builder after retriving data from excel.

    I am using string bulider to append the data to the table and after that insert into database.

    Dim sbstr as new stringbuilder
    sbstr.append()
    sbstr.tostring=insert into tableA(A,B,C,D,E,F) values(ram,sham,nitin,rahul,nilesh,)

    how i will remove the last comma(,) only not nilesh and get the below string so that it will insert into table
    insert into tableA(A,B,C,D,E,F) values(ram,sham,nitin,rahul,nilesh)

    I need above string

    Best Regards,
    Sandip Raut
  • #750180
    Hi,

    You can use the trim or remove function to remove it.

    Try the below one.

    string test1 = "0123456";
    test1 = test1.Remove(test1.Length - 1);

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/

  • #750202
    hi
    sandip

    Try this code using the command substring with length for that remove the string.Here I post vb.net and c# code here try and let me know


    protected void Button6_Click(object sender, System.EventArgs e)
    {
    string st = "insert into tableA(A,B,C,D,E,F) values(ram,sham,nitin,rahul,nilesh,)";
    string st2 = st.Substring(1, st.Length - 3)+")";
    }

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    Dim str As String = "insert into tableA(A,B,C,D,E,F) values(ram,sham,nitin,rahul,nilesh,)"
    Dim st1 As String = str.Substring(1, str.Length - 3) + ")"
    End Sub

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #750206
    Hi,

    Refer below sample code for your reference.


    string val="abcdefg";
    val=val.Remove(val.Length-1);


    Try something like above to achieve your goal...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #750214
    Hello sandip,

    Don't repeate same question again in this forum.
    If you want to change question than you can edit previous one.
    Repeatation doesn't helps you to find out solutions, it is type of violations in this forum.

    Regards,
    Nirav Prabtani (Senior Web Developer)
    Email : niravjprabtani@gmail.com
    blog : niravprabtani.blogspot.in

  • #750327
    If you want to try this with SQL please use the below Query




    Declare @ColVal as varchar(100)
    Set @ColVal = 'ram,sham,nitin,rahul,nilesh,'


    Select reverse(stuff(reverse(@ColVal), 1, 1, '')) As Vals

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments