Reputation: 982
I'm tasked with changing an older website and adding functionality of a third party API. For this API to work, some data from the database must be modified based on certain conditions.
The code is as follows:
<asp:Label ID="AccLabel" runat="server" Text='<%# Eval("Acc") %>' Width="96px"/>
The data in the database has this field in a variety of formats depending on the table. For example's sake, we'll say A1965445. Currently the website shows that format for the data, however for the API to accept the query, the data needs to be in the following format: A19-65445
Different tables in the database will have hyphens at different locations.
I don't want the data changed in the database, only for the user on the website. The API call just looks at the rows on the current page before making the call.
Thank you
Upvotes: 0
Views: 58
Reputation: 5068
Try
Eval("Acc").ToString().Substring(0, 2) + "-" + Eval("Acc").ToString().Substring(3)
Upvotes: 1
Reputation: 2153
You can call .ToString()
and then do simple string manipulation on the value. I would insert the dash character at the specific index you need it (in your sample: 2
):
<asp:Label ID="AccLabel" runat="server" Text='<%# Eval("Acc").ToString().Trim().Insert(2, "-") %>'
Width="96px" />
If you need to move the dash (ex: A1965-445
to A19-65445
) then remove all dashes and insert the one you want:
Eval("Acc").ToString().Trim().Remove("-", "").Insert(2, "-")
Upvotes: 1