Returning a string within a string

sherbug1015
sherbug1015 used Ask the Experts™
on
I am trying to create a function that will find the position of a word in a string and return the word.
For example, if I want to return the word Asian, then I would pass into the function the following parameters:

ProfileResponses = "1578:English,1579:English +,1580:H.I.T.,179108:Chinese,179109:Korean,179110:Vietnamese,230434:Asian,"
ProfileParameter = 230434

 Private Function ParseProfileResponse(ByVal ProfileResponse As String, ByVal ProfileParameter As String) As String
            Dim line As String = ProfileResponse
            Dim data() As String
            Dim position As Integer
            Dim result As String = ""
            Dim parameter As String = ProfileParameter

            data = line.Split(","c)
 

            For Each s As String In data
                position = s.IndexOf(parameter)  
                If position > 0 Then
                    result = ??????????? -  I need to return just the word Asian.  Can someone help me with this.  
                    Exit For
                End If

            Next
            Return result
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Here goes
    Function ParseProfileResponse(ByVal ProfileResponse As String) As String
        Dim Result = (From x In ProfileResponse.Split(",") Where x.Split(":")(1) = "Asian" Select x.Split(":")(0)).FirstOrDefault
        Return If(Result.Length = 0, "Error", Result)
    End Function

Open in new window

Most Valuable Expert 2012
Top Expert 2014

Commented:
Try

return s.split(":")(1)

Commented:
Hmm! even better try
    Function ParseProfileResponse(ByVal ProfileResponse As String, ByVal ProfileParameter As String) As String
        Dim Result = (From x In ProfileResponse.Split(",") Where x.Split(":")(0) = ProfileParameter Select x.Split(":")(1)).FirstOrDefault
        Return If(Result.Length = 0, "Error", Result)
    End Function

Open in new window

Try This:-
Private Shared Function ParseValue(value As String, key As String) As String
	Return value.Split(","C).Where(Function(s) s.Split(":"C)(0) = key).[Select](Function(s) s.Split(":"C)(1)).FirstOrDefault()
End Function

Open in new window

Top Expert 2011
Commented:
Please try:
Private Function ParseProfileResponse(ByVal ProfileResponse As String, ByVal ProfileParameter As String) As String
	Dim line As String = ProfileResponse
	Dim data() As String
	Dim position As Integer
	Dim result As String = ""
	Dim parameter As String = ProfileParameter

	data = line.Split(","c, ":"c)

	position = Array.IndexOf(data, parameter)
	
	If position > 0 Then
		result = data(position + 1)
	End If

	Return result
End Function

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial