Hi, I cant seem to convert the following into vc++ from vb.net.

Dim i As Integer
Dim address As String = myReader.Item("Address")
Dim addresses() = address.Split(" ")
Dim secondPartIndex As Integer
For i = 0 To addresses.Length - 1
   If Regex.IsMatch(addresses(i), "^\D{1,}$") And secondPartIndex = 0 Then
          secondPartIndex = i
   End If
Next

Can someone show me how its done please? Thanks

Edited 6 Years Ago by shakssage: n/a

The problem is not the loop, the problem is the regex... I am not sure how to go about it.

haha, yeah, i've noticed that too. But I cant get the for loop converted, let alone the regex lol. What I'm trying to do is take a string of an address of the format;
"houseNo streetName, Town, County, PostCode" and then break it up and place the results seperately into Textboxes.
It worked when I did it on VB.Net. Just can't do it on vc++.

If you are using C++/CLI you should be able to use the Regex portion of the .NET library. See http://msdn.microsoft.com/en-us/library/3y21t6y4.aspx for the namespace and syntax. If you're trying to do it to native C++, Taywin is correct, and you'd have to find a library to do your Regex processing (I don't have any experience in that area beyond what there is in .NET). It will be helpful to know if you want to do it under managed or unmanaged code. If you need to do a lot of conversion automatically, there are products such as http://www.tangiblesoftwaresolutions.com/Product_Details/VB_to_CPlusPlus_Converter_Details.html (again, never used it, can't speak for it) to do so.

Rather than focusing on how to convert the for loop, relearn how to do it in C++. There are some nuances, but basically it's the same. You know you don't have to "dimension" variables in C++, you can just say int i; instead.

I'm trying to convert it to Visual C++, So that would fall in the C++/CLI category?

Thanks for the links, unfortunately I still can't convert the code. For the for loop, I can create a variable holding "addresses.Length - 1". Then it should be straightforward.

Shouldn't it be straightforward converting from vb.net to vc++? lol. Pain in the backside so far :(

It would just be addresses->Length - 1 (the ^ in String ^ means it is a handle, so its members are accessed in the same way as if it were a pointer.

Both VB.NET and VC++.NET are converted to the same intermediate language (IL), but the syntax isn't necessarily going to be similar. There should be a way to call your VB code from C++/CLI but I have never done that.

Yeah, I've also read that you can link the code, one of the advantages of visual studio, but I'm supposed to do this in c++ only, so that's not an option.

My original plan was to take a string of an address and split it into several textboxes, as I managed to do it in VB.Net. However, it's not the end of the world if I don't do it like that. I can just take a much more simpler approach and stick the whole string into a richTextBox :).

If someone is able to convert that code into VC++, please do so if it's not too much to ask.

Thanks for all the help.

I know the issue that I'm having, and perhaps the other are as well, is that if you don't know enough about the syntax of basic control structures in C++ and/or C++/CLI then someone translating it for you is not going to do you any good. I'm not trying to be mean, I'm just being realistic with you.

Run through a tutorial like http://www.functionx.com/cppcli/index.htm (a bit outdated but still valid), and the first couple of lessons should show you what you need to know.

If you can, use VC++ 2008 Express as the 2010 Express and Full do not have good intellisense for C++/CLI.

If your method doesn't work then post back with specific concerns about lines that you cannot convert. Line 3 is an array, which may not be so evident from its VB call.

This article has been dead for over six months. Start a new discussion instead.