• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 858
  • Last Modified:

ASP.NET / VB: Replace US State Abbreviations with Names

How can I replace state abbreviations with state names using ASP.NET and VB?

<%@ Page Language="VB" AutoEventWireup="false" %>
<% 

Dim array(,) As Object = { _
     {"ak","Alaska"}, _
     {"al","Alabama"}, _
     {"ca","California"} _
}

Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"

Response.Write(xyz)
' Should say:
' Lakes in Alaska are cold cold but it is always hot in Alabama and can be hot or cold in California

%>

Open in new window

0
hankknight
Asked:
hankknight
1 Solution
 
CodeCruiserCommented:
I would change array to Dictionary(of string, string) and then loop through it doing a Replace on the string.

Dim states As New Dictionary(of string, string)
states.add("AK", "Alaska")
states.add("AL", "Albama")
states.add("CA", "California")
...

Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"

For Each (state as string in states.Keys)
  xyz = xyz.Replace(" " & state & " ", " " & states(state) & " ")
Next
0
 
hankknightAuthor Commented:
Thanks but I get an error.

I posted a related question here:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27867280.html
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now