Ask: Replace multiple new line into single new line or br - asp.net

I have problem with replace character.
If I have one textbox, and I write into textbox with many new line.
and the results I wanted a lot of new lines replaced with one or two new lines such as comments in the facebook.
I'l try this code :
litText.Text = System.Text.RegularExpressions.Regex.Replace(Text1.Text, "[\\r\\n]+", "<br /><br />", System.Text.RegularExpressions.RegexOptions.Multiline);
this works if I press a lot of button enter,but this isn't works if I press button enter once then displays new line twice. I want if I press once or two button enter, fixed display once or two new line. except three times or more than two.
please your assistance and your opinions.
Thank you

You want to duplicate the entire \r\n multiple times, as opposed to just duplicating one of them like in your example. Also you should use #"..." for this.
litText.Text = System.Text.RegularExpressions.Regex.Replace(
Text1.Text, #"(\r\n|\r|\n)+", "<br>",
System.Text.RegularExpressions.RegexOptions.Multiline);

Related

How do I advance to the next occurrence of a variable in R Studio IDE

When I highlight any string of text in the R Studio console a rectangle is drawn around all other occurrences of this same string of text. How do I advance to the next occurrence of this arbitrary string of text? I'd like the keyboard shortcut.
CTRL-F3 is the closest shortcut I know. This takes the selected string of text, drops it into the Find dialog and jumps to the next occurrence (keep pressing CTRL-F3 to cycle through)
If you would like to move to the next occurrence of a word/variable and select it while also keeping the original selected, this command exists but does not have a default shortcut assigned to it.
The command is called 'Find and add next' (or 'Quick Add Next' in older versions). You can assign a shortcut to it by going into Preferences -> Code -> Modify_Keyboard_Shortcuts. I use Alt+Cmd+Right (on a Mac) as that is an unassigned key binding.
You can see bellow I have used the command twice to select three of the four instances.
On a Mac, I use command+f to call Find with a selected string and then use control+g to move onto the next match.
This needs to be over 30 characters, but only needs 2:
F3

How do I run the same piece of code for multiple text inputs without using select case?

I have eight aspx text inputs labelled txtBoookingId1, txtBookingId2 etc etc. I have a sub which handles eight buttons clicks as the code is more or less the same for each. I have it so it knows which one is pressed. I want to run "booking = System.Text.RegularExpressions.Regex.Replace(txtBookingId2.Text.Trim, "[^0-9.]", "")" to trim off any letters but I want the txtBokingId2 part to be the correct one based on which button was clicked.
Is there an easier way of doing this than using a Select with eight cases and the same line of code in each with only the bolded above changed slightly? I tried having a string "Dim txt As String = "txtBookingId" & btnPressed.ToString" (which would give txtBookingId1, txtBookingId2 etc based on button then using that in place of txtBookingId2 but it's not valid code as there isn't an text input named "txt".
Code decides which button is clicked based on where CommandArgument=1,2,3 in the text input etc

Gridview with SQL data source is removing white spaces

I have a GridView connected to my database through an sql data source. It is bound by the follow code:
firstview = "SELECT ID, DC, DD, CYM, CB, ST FROM SCH_SCHEMANAME.TABLENAME WHERE CI = " & txtboxvalue.text & " AND ST = 'whatever' AND D = 0"
SqlDataSource1.SelectCommand = firstview
GridView1.DataBind()
There is no problem connecting to the database. Inside the database, one of the column contains extra whitespace. To make a long story short, the DD column is a short sentence that contains more than one space between some words. e.g. "This_is____a_sentence_stored___in_the_____dd_column" where each underscore is a space in this example.
When I do the databind, the spaces in between the words are all reduced to 1 space. I do, however, need to keep the exact amount of spaces between each word when the data is bound in the GridView. At the moment, it is showing in the GridView as "This_is_a_sentence_stored_in_the_dd_column" but I want to keep the amount of spaces rather than have them automatically cut down.
Can anyone help?
I was able to fix by doing the following on the RowDataBound event for the gridview.
e.Row.Cells(4).Text = e.Row.Cells(4).Text.Replace(" ", " ")
The database was retrieving the correct value, but the spaces were being parsed/encoded. JPW's links helped me with the line of code.
Thanks
It is not about a database. The browser treats multiple spaces as one. E.g. see several workarounds here: http://www.codeproject.com/Articles/30740/Avoid-Multiple-Space-Elimination-in-ASP-NET-GridVi

Adding new lines to Alert text

I want to create a simple multiline Alert popup
Alert.show("Blah\\nBlah")
shows Blah\nBlah when what I really want is two lines, one Blah each.
If it is anything like most languages, then you only need to have \n to get a new line. having \\n is saying that you actually do want to draw a \ because normally the back slash is used to say you're about to do some thing special.
Try:
Alert.show("Blah\nBlah")

asp.net: explicit localization & combining strings

This seems like it should be a simple thing to do, but I can't figure it out.
I have a localized resource that I'm using in two places - one as a col. header in a datagrid, and then as a descriptor beside a field when the user edits a row.
The text of the label looks like:
Text="<%$Resources:Global,keyName%>"
However, I'd like to add a trailing : to the label - except if I change the above to
Text="<%$Resources:Global,keyName%>:"
then the : is the only thing that shows up! I've tried it with simple strings, so there's nothing special about the colon char that causes this.
Surely I don't have to have 2 different resources?
Have you tried Text="<%$Resources:Global,keyName%>" + ":" ?
You'd basically be concatenating two strings. Or treat them as two strings
StringBuilder t;
t.append(<%$Resources:Global,keyName%>)
t.append(":")
Text = t;
Assuming you need to keep the : together for styling reasons, replace the label with a span:
<%=Resources.Global.keyName %>:
Well, sometimes the obvious isn't so obvious until someone else looks at it:
Text="<%$Resources:Global,keyName%>" /> :
Just move the : outside the label tag, and all is well.

Resources