deanlee17
asked on
Searching string and replacement
Hi experts,
Trying to check the first char of a string. If its aminus I want it stripped out, if one doesnt exist then I want it added.
Thanks.
Trying to check the first char of a string. If its aminus I want it stripped out, if one doesnt exist then I want it added.
Thanks.
If IsDBNull(FlxGridInvoiceInfo(remove_minus, 14)) = False And (FlxGridInvoiceInfo(remove_minus, 15) = "Stock Adj") Then
if first char is a minus strip it out
Else
place a minus before the value
End If
End If
I do not see the string in you code, but here is a way to do it, given a string called s.
s = (-CInt(s)).ToString
s = (-CInt(s)).ToString
ASKER
The string will be the value in the flexgrid as it looks through...
FlxGridInvoiceInfo(remove_ minus, 14)
FlxGridInvoiceInfo(remove_
And how do you reference the value in the flexgrid? Sorry, flexgrid is not a standard control and I do not use it, so I cannot give you the exact syntax.
Maybe something similar to this:
grid.Cells(remove_minus,3) .Value = (-CInt(grid.Cells(remove_m inus ,3).Value)).ToString
Maybe something similar to this:
grid.Cells(remove_minus,3)
ASKER
Ok thanks. What is the common way to insert a value into a string?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>If its aminus I want it stripped out, if one doesnt exist then I want it added.
Generally speaking, you can use string functions
Dim str as String = "-123"
If str.StartsWith("-") Then
Str.TrimStart("-")
Else
Str = "-" & str
End If
Generally speaking, you can use string functions
Dim str as String = "-123"
If str.StartsWith("-") Then
Str.TrimStart("-")
Else
Str = "-" & str
End If
Manipulating strings as suggested by CodeCruiser can lead to problems in some situations.
The format of a negative number, including the position of the -, can be changed in the configuration panel. Assuming - at the beginning can lead to problems. You could well end up with -123- instead of removing the -.
This is why, in my solutions, I convert to an Interger and then back to a String. The conversion will take care of any format set in the Control Panel.
The format of a negative number, including the position of the -, can be changed in the configuration panel. Assuming - at the beginning can lead to problems. You could well end up with -123- instead of removing the -.
This is why, in my solutions, I convert to an Interger and then back to a String. The conversion will take care of any format set in the Control Panel.
ASKER
Ok just trying both solutions to see what i get,
Code cruiser yours errored with....
MissingMemberException
Public member 'StartsWith' on type 'Single' not found.
Code cruiser yours errored with....
MissingMemberException
Public member 'StartsWith' on type 'Single' not found.
ASKER
So ive now tried..
Didnt error but when the msgbox displayed the value it had not trimmed off any minuses
Thans
Didnt error but when the msgbox displayed the value it had not trimmed off any minuses
Thans
If IsDBNull(FlxGridInvoiceInfo(remove_minus, 14)) = False And (FlxGridInvoiceInfo(remove_minus, 15) = "Stock Adj") Then
If FlxGridInvoiceInfo(remove_minus, 14).ToString.StartsWith("-") Then
FlxGridInvoiceInfo(remove_minus, 14).ToString.TrimStart("-")
MsgBox(FlxGridInvoiceInfo(remove_minus, 14))
Else
MsgBox("Something")
End If
ASKER
Nailed it, see attached....
If IsDBNull(FlxGridInvoiceInfo(remove_minus, 14)) = False And (FlxGridInvoiceInfo(remove_minus, 15) = "Stock Adj") Then
Dim Thestring As String = FlxGridInvoiceInfo(remove_minus, 14)
Dim addminus As String = "-"
If Thestring.StartsWith("-") Then
Thestring = Replace(Thestring, "-", "")
FlxGridInvoiceInfo(remove_minus, 14) = Thestring
Else
FlxGridInvoiceInfo(remove_minus, 14) = addminus & Thestring
End If
End If
ASKER
Dim remove_minus As Integer
For remove_minus = 1 To FlxGridInvoiceInfo.Rows.Co