Solved

Searching string and replacement

Posted on 2011-09-22
11
157 Views
Last Modified: 2012-05-12
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.
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

Open in new window

0
Comment
Question by:deanlee17
  • 6
  • 4
11 Comments
 

Author Comment

by:deanlee17
ID: 36580772
These are the top few lines too...

Dim remove_minus As Integer
For remove_minus = 1 To FlxGridInvoiceInfo.Rows.Count - 1
0
 
LVL 40
ID: 36580893
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
0
 

Author Comment

by:deanlee17
ID: 36580905
The string will be the value in the flexgrid as it looks through...

FlxGridInvoiceInfo(remove_minus, 14)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 40
ID: 36581021
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_minus ,3).Value)).ToString
0
 

Author Comment

by:deanlee17
ID: 36581027
Ok thanks. What is the common way to insert a value into a string?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36581254
If the value is already a String, simply assign it directly:

Dim s As String
s=value

If not, the following does the job for most types of values:

Dim s As String
s=value.ToString

If not, then the value might have another method to do that:

Dim s As String
s=value.<Other Method>
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36582141
>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
0
 
LVL 40
ID: 36582423
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.
0
 

Author Comment

by:deanlee17
ID: 36585518
Ok just trying both solutions to see what i get,

Code cruiser yours errored with....

MissingMemberException
Public member 'StartsWith' on type 'Single' not found.
0
 

Author Comment

by:deanlee17
ID: 36585661
So ive now tried..

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

Open in new window

0
 

Author Comment

by:deanlee17
ID: 36585829
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

Open in new window

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBScript Issues 8 34
Crystal reports vb.net 2 41
VB.NET (2008) - Refactoring Question 2 21
vb.net and creating a class 5 17
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question