Above is a database that i am uploading to a hosting server to pull the data off of it to a website using .asp code in a HTML file. The sensors field gets the data using lookup from another table and can contain multiple values but these values are separated using a comma ",". I was wondering if there was a way either within the database or on the .asp page to get rid of the comma and sort them in a new paragraph or replace the "," with "< br/ >" between each of the sentences
NOTE CHANGE TO ORIGINAL QUESTION
The original question was in reference to ASP.NET. After providing a thorough answer it transpired that the author was actually using VBScript and Classic ASP. The final update to this answer reflects his change.
I have left my original answer just in case it helps someone else with the same issue as originally asked..
===================================
Replace won't be enough if you want to change any of the order; I.E alphabetically.
One way would be to put the Database string into a list, splitting it at the comma. you can then output this list in any order you want.
For example.
to Split into a list
List<string> myList = yourSensorsString.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
You can then order this however you see fit. Something like:
myList.Sort();
Then simply go through each of the items, like - where myLbl is perhaps a label control on your page
foreach ( str in myList) {
myLbl.Text += str + "<br />";
}
Or as separate paragraphs, maybe into a Literal
foreach ( str in myList) {
myLit.Text += "<p>" + str + "</p>";
}
Update
This code example above would be placed in your code-behind. You would get your sensors string from the database, and then split it into a list, then output to the HTML. No need to get your database to perform this sort of logic.
I have also assumed C# as you never mentioned what flavour of .net you're using.
Update 2
After looking at your fiddle, i edited it slightly to show where you can use this sort of code. Also converted my code to VB. Hope this helps. Can't put any more time into this... Fiddle Is Here
Update 3
The original question was for ASP.NET - as it turns out, it's actually Classic ASP the OP is asking about.
So split your string like this:
myList=Split(rsLogbook("FieldName"), ",")
for each str in myList
document.write(str & "<br />")
next
Other than that, I can't help any further - lot of time spent on this :)
Related
I am working on an excel sheet, which collects data from a website. A few words about this website:
- it is independant from me, I can not change its struckture
- it should look like a table, but it is not. The structure is like this:
<h4>blabla</h4><span class="address">blabla</span><span class="state_x">blabla</span>
<h4>blabla</h4><span class="address">blabla</span><span class="state_x">blabla</span>
<h4>blabla</h4><span class="address">blabla</span><span class="state_y">blabla</span>
The trick is the "state_?" class, its name can change (but only the end of it).
What am I doing now?
- collect all the data into arrays
- of course I will get "state_x" and "state_y" arrays
- go through the arrays, and write everything to a sheet
The problem:
When I get to the "state_?" arrays, I already don't know, where its data came from.
The best would be to have only one "state" array, which can collect data from any "state_?" classes. Of course this code doesn't work, but to show the logic:
Dim state As Variant
Set state = ieApp.Document.getElementsByClassName("state_*")
How could this work? Any help is appreciated, please consider, that I am new in vba.
NEW INFOS
I have found some further help by analysing the source HTML code. Each row is nested in a <div class="listitem"> </div>. Is it possible to create an array, where each element is a complete "listitem" div, and with a for loop extract the data from these elements, as written above?
Each "listitem" div can contain only one "state_?" class. So this way I wouldn't loose the information, where the data comes from.
Try querySelectorAll with selector e.g. "*[class^='state_']" which should select all elements which have class name that starts with text state_. More about selectors here. HTH
Dim states As IHTMLDOMChildrenCollection
Set doc = ie.document
Set states = doc.querySelectorAll("*[class^='state_']")
If (Not states Is Nothing) Then
Dim i
For i = 0 To states.Length - 1
Debug.Print states(i).innerHTML
Next i
End If
I'm stuck here. Everytime I concatenate SSRS textbox, the concatenation adds a new line. I use a Microsoft SQL 2013 database. Here is my expression that I use to concatenate.
=First(Fields!FirstName.Value, "DataSet1") & " " & First(Fields!LastName.Value, "DataSet1)
What happens is that there is a new line placed after the first name making the final output look like this.
FirstName
LastName
If anyone has any suggestions that would be great. I tried googling the problem and I couldn't find an answer. Please someone help.
Try using a variable under Report/Report Properties or even concat it on the query end...it may be easier
Perhaps you have leading/trailing spaces. Try using LTRIM or RTRIM.
=First(LTRIM(RTRIM(Fields!FirstName.Value)), "DataSet1")
& " " & First(LTRIM(RTRIM(Fields!LastName.Value)), "DataSet1)
I have found what was wrong. I had to select my expression (Expr). Then in the properties tab, I changed the Markup Type to HTML and that fixed my problem.
Thank you everyone for your time and effort.
Hello on excel i have big data.Is only one column the data and i want split by tags "{" and "}". On column the image is like that:
{{[math1];1;1;5.6617};{[math2];1;1;34.3131};{[math3];1;1;4.5293}}
If i format the text is like that:
{
{[math1];1;1;5.6617}; //Math1
{[math2];1;1;34.3131}; //Math2
{[math3];1;1;4.5293} //Math3
}
i want split //Math1 , //Math2 & //Math3
The data is from SQL server maybe help this. I can use any tool extra on excel for data model?
Following should be helpful though not sure its the best way to solve your problem.
For first part i.e. Math1, use the following formula
=MID(A1,2,SEARCH("};",A1,1)-1)
For second part i.e. Math2, use the following formula
=MID(A1,SEARCH("};",A1,1)+2,SEARCH("};",A1,SEARCH("};",A1,1)+1)-SEARCH("};",A1,1)-1)
For third part i.e. Math3, use
=MID(A1,SEARCH("};",A1,SEARCH("};",A1,1)+1)+2,LEN(A1)-SEARCH("};",A1,SEARCH("};",A1,1)+1)-2)
See image for reference
Anyone knows how to get list of selected CheckBoxList values from Umbraco using ContentService?
I use contentService.GetValue("currencies")
and I get string with numbers and commas something like "154,155,156,157"
How can I get actual values?
Does anyone know how to do it using DataTypeService?
As it was mentioned above, you can use Umbraco helpers method to retrieve string value for the PreValue id.
Umbraco.GetPreValueAsString([PreValueId])
You can find more about it here: https://our.umbraco.org/documentation/reference/querying/umbracohelper/#getprevalueasstring-int-prevalueid
It's calling database directly through the DataTypeService behind the scene. It's worth to reconsider it and close it on another type of property / data type to avoid calling database on the frontend layer and just retrieve data from IPublishedContent cached model.
Read also about common pitfalls and anti-patterns in Umbraco: https://our.umbraco.org/documentation/Reference/Common-Pitfalls/
Those are prevalues.
From that given string, you have to split those and get the real value by calling one of umbraco library umbraco.library.GetPreValueAsString(123);
For example.
foreach(var item in contentService.GetValue("currencies").Split(',')) {
var realValue = umbraco.library.GetPreValueAsString(int.Parse(item);
}
You have 2 nulls because prevalues sometimes has blank values on it, like "121,56,,15,145".
You need then to modify your split code like this
foreach (var item in value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
}
StringSplitOptions.RemoveEmptyEntries will ignore empty spaces.
I am trying to query from search box using list of data and the linq I used is:
data = (From k As BSPLib.ContactLib.Contact In data_org.Values Where k.stringdata Like "%" & Searchtxtbox.Text & "%" Select k.prime).ToList
But this is not working, I am getting no data at all. Data_org is a dictionary so I used the values; k.stringdata contains all the data that need to be searched. Searchtxtbox.text contains the user defined search item.
I Tried with sqlmethods through linq, but sqlmethods does not exist for me, I tried with with Imported namespace yet the code is not showing sql methods, could you please provide a workable query or just tell me where I have gone wrong. Thank you.
My Visual Basic is a bit rusty so forgive me if I have the syntax wrong:
One thing you could use is Contains which will be similar to "%Searchtxtbox.Text%"
and exactly the same if it is used with a DatabaseContext.
I know it is not the same as Like but if that doesn't work than likely something else is wrong and than I would like more code.
data = (From k As BSPLib.ContactLib.Contact In data_org.Values Where k.stringdata.Contains(Searchtxtbox.Text) Select k.prime).ToList
You can additionally use StartsWith and EndsWith for "Searchtxtbox.Text%" and "%Searchtxtbox.Text"
Also would I like to suggest to puth "%" & Searchtxtbox.Text & "%" between Parentheses for clarification, but that's all up to you.
The % wildcard character won't work here, remember this is .NET code, not SQL. You need something like this instead:
data = (
From k As BSPLib.ContactLib.Contact In data_org.Values
Where k.stringdata.Contains(Searchtxtbox.Text) Select k.prime).ToList