Remove Value from string

Results 1 to 2 of 2

Thread: Remove Value from string

  1. #1
    Kok Leong Guest

    Default Remove Value from string

    I have problem in remove a value from string.<BR><BR>My string contains some values where each value is seperated with ",". <BR><BR>When I delete any value in string, it won&#039;t delete the ",".<BR><BR>How to determine when the value that need to be delete is not situated in the last position, my function will delete the value +"," and when the value to be remove is in last position of the string, it won&#039;t delete the value without ","?<BR><BR>I have my function to do the deletion stated below.<BR><BR>Function RemoveOnce(strExpression, strRemove)<BR> Dim iStartPos, iStopPos, strLeft, strRight<BR> Dim iLeftLen, iRightLen<BR> iStartPos = Instr(1, strExpression, strRemove, 1)<BR> iStopPos = iStartPos + Len(strRemove) - 1<BR> iLeftLen = iStartPos - 1<BR> iRightLen = Len(strExpression) - iStopPos<BR> strLeft = Left(strExpression, iLeftLen)<BR> strRight = Right(strExpression, iRightLen)<BR> RemoveOnce = strLeft & strRight<BR>End Function<BR><BR>Function Remove(strExpression, strRemove)<BR> Dim strExpressionCopy<BR> StrExpressionCopy = strExpression<BR> Do while Instr(1, strExpressionCopy, strRemove, 1) &#060;&#062; 0<BR> strExpressionCopy = RemoveOnce(strExpressionCopy, strRemove)<BR> Loop<BR> Remove = strExpressionCopy<BR>End Function<BR><BR>TempList = "R1, R2, R3, R4, R5, R6"<BR>NewList = "R1"<BR>TempList = Remove(NewList,Remfile)<BR><BR><BR>This is my code looks like... <BR><BR>Pls help

  2. #2
    Mike Shaffer Guest

    Default RE: Remove Value from string

    How about doing something more like this:<BR><BR>function Remove(strExpression, strRemove)<BR><BR>&nbsp;&nbsp;&nbsp; dim aryTemp, intX, strNew<BR>&nbsp;&nbsp;&nbsp; aryTemp = split(strExpression, ",")<BR>&nbsp;&nbsp;&nbsp; for intX = 0 to ubound(aryTemp)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp; if aryTemp(intX) &#060;&#062; strRemove then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if intX &#062; 0 then strNew = strNew & ","<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp; strNew = strNew & aryTemp(intX)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp; end if<BR>&nbsp;&nbsp;&nbsp; next<BR><BR>&nbsp;&nbsp;&nbsp; remove = strNew<BR><BR>end function<BR> <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts