Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

.NET string

I have a string that is given to me as a XML POST response from another server. its a delimited string, I have already tokenized the string.

so now I have for example

firstName=john
lastName=Smith
telephone=514-555-1234
email=jsmith@email.com

what I would like to do is
create some kind of table so they are aligned, I was thing plain labels but im sure there is a better way then this.
Im looking for this:

First Name:   John
Last Name:   Smith
Telephone:   514-555-1234
Email:            jsmith@email.com
0
prowebinteractiveinc
Asked:
prowebinteractiveinc
  • 5
  • 4
  • 3
  • +2
2 Solutions
 
mwochnickCommented:
what/where do you want to display the table?  web page, file, etc?
0
 
käµfm³d 👽Commented:
What kind of project is this? WinForms? ASP.NET?
0
 
prowebinteractiveincAuthor Commented:
windows forms
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
prowebinteractiveincAuthor Commented:
I need to create the textboxes dyanically, strings could change, I could get more variables or less.. so for every

variableName=variable I need 2 textboxes on for the variableName, nad one for the variable, I will worry about the design/look later
0
 
Ron MalmsteadInformation Services ManagerCommented:
"firstName=john
lastName=Smith
telephone=514-555-1234
email=jsmith@email.com
"

'Something like this...

Dim Fields as String() = FieldData.Split(vbcrlf)

Dim i as integer = 0
Dim Field as string
For Each Field in Fields

'create a control
Dim txtDyn as TextBox
Dim lblDyn as Label

'give controls a unique ID including the field data type.
txtDyn.ID = txt &  Field.Split("=").getvalue(0).tostring & i.tostring
lblDyn.ID = lbl & Field.Split("=").getvalue(0).tostring & i.tostring

'Give it a text value
txtDyn.Text = Field.Split("=").getvalue(1).tostring
lblDyn.Text = Field.Split("=").getvalue(0).tostring

'Make them visible
txtDyn.Visible = True
lblDyn.Visible = True

'add the control to a panel or other control container
Panel1.Controls.Add(lblDyn)
Panel1.Controls.Add(txtDyn)


i=i+1
Next
0
 
mwochnickCommented:
Add a TableLayoutPanel to your form. At runtime, instantiate your controls using the new keyword. Add them to the tableLayoutPanel.Controls collection. You can either add them to specific rows and columns, or let panel have them flow into the next available cell.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Why not just use a DataGridView?  You can turn off headers, row selectors, etc, and make it read-only and set the columns to autosize to the max width of the values in the table.

Adding values is as easy as:

        DataGridView1.Rows.Add("First Name:", "John")
        DataGridView1.Rows.Add("Last Name:", "Smith")
        DataGridView1.Rows.Add("Telephone:", "514-555-1234")
        DataGridView1.Rows.Add("Email:", "jsmith@email.com")

But of course you can use variables instead of hard-coded values...

Here's what it could look like: *There are many possible configurations of the properties*
One possible DataGridView configuration
0
 
prowebinteractiveincAuthor Commented:
what is the vbcrlf  ?

Dim Fields as String() = FieldData.Split(vbcrlf)

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
vbCrLf is a constant that stands for "Carriage Return/Line Feed". The code snippet is breaking up the FieldData string so that each line ends up as a separate entry in the Fields array.
0
 
prowebinteractiveincAuthor Commented:
I seem to have the string cut up, the problem through is the variable name shows up as firstName, is there a way to change it to First Name, or Name, or as anything I want really

so you know what route I took..

I used the logic of the logic for the splitting xuserx2000 and then put in a DataGridView exactly like Idle_Mind said
0
 
prowebinteractiveincAuthor Commented:
I was thinking of creating an array of the names I want, I know how to do this in PHP but in .NET, I need alittle help
0
 
mwochnickCommented:
here is some example for how to use xmlReader and how grab the content of an XML document
http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx#Y0
it has both c#.NET and VB.NET examples.  It links to more in depth examples on how to do specific actions

Here's an a document on how to create and populate an array with values
http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx
and here's c# tutorial on arrays
http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"the variable name shows up as firstName, is there a way to change it to First Name, or Name"

You can find the all the Capital letters in the string and add a space before each one:
        Dim data As String = "firstName"
        data = FormatValue(data)
        Debug.Print(data)

Open in new window


Using this function:
    Private Function FormatValue(ByVal str As String) As String
        Dim SB As New System.Text.StringBuilder(str)

        If SB.Length > 0 Then
            ' make sure the first letter is capitalized
            SB(0) = Char.ToUpper(SB.Chars(0))

            ' Working backwards, add a space before each capital letter found:
            For i As Integer = SB.Length - 1 To 1 Step -1
                If Char.IsUpper(SB.Chars(i)) Then
                    SB.Insert(i, " ")
                End If
            Next
        End If

        Return SB.ToString.Trim
    End Function

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now