How to replace certain part of dynamic string - asp.net

I want to replace a certain part of dynamic string in vb.net. I will try to explain it in this example:
I have a STRING like this:
&12=1005&14=96&230=28&1116=0074005&1271=45&1272%3d001002003%2612%1276=1
and I want this part 3d001002003 to be changed with some other text that I have entered in a Textbox (or any other element).
Problem is that this STRING is sometimes different in character size:
&12=1005&14=96&230=28&1116=0074005&1271=45&1272%3d001002003%2612%1276=1
&12=15&14=96&230=28&1116=0075&1271=45&1272%3d021022023%26276=1... and so on.
Only constant thing in this STRING is that part which needs to be changed always starts with 3d and always has 11 characters. So, something what I'm looking for is to find the part of string that starts with 3d and contains 11 characters and then replace it with some other content from Textbox.
Thanks in advance!

try using below regex
^3d(?!.* )(?=.*[\w-])[\w -]{11}$
(starting with 3d with following total 11 characters)
OR
^%3d[0-9]{9}%
(starting with %3d with following total 9 numeric(assuming only numeric in-between) ending with % = total 11)
in vb.net
example:
Console.WriteLine(Regex.Replace("&12=15&14=96&230=28&1116=0075&1271=45&1272%3d021022023%26276=1", "%3d[0-9]{9}%", "%R%", RegexOptions.IgnoreCase))

Related

Pattern lookup within a string in R using regular expression matching

I am trying to pick patterns within a specific string and their respective location. I have explained below with an example:
String = "Web_797-Web_797-Web_797-Web_797-PCP_IM_PAR-Pharm_1-Pharm_1-
Web_797-PCP_IM_PAR-Prior_OP-Web_797-Prior_OP-Event_0-"
pattern = "Web_797-*Web_797" (Web_797 followed by Web_797 with anything in between)
I used the following function:
str_locate_all(String,pattern)[[1]]
I am getting the following result:
start end
[1,] 1 15
[2,] 17 31
which is what I need partially. However I the pattern is not able to pick the following combination (highlighted in black).
String = "Web_797-Web_797-Web_797-Web_797-PCP_IM_PAR-Pharm_1-Pharm_1-
Web_797-PCP_IM_PAR-Prior_OP-Web_797-Prior_OP-Event_0-"
I would appreciate if anyone could help with this. I believe there is something wrong with the way I am defining the pattern but not able to fix it.
The problem with your pattern pattern = "Web_797-*Web_797" is the -* part. That means zero or more dashes (-). I believe what you wanted was a dash followed by any characters. So a first (incorrect) attempt would be
pattern = "Web_797-.*Web_797" Where the . means "any character". But that is not quite right. You only want to collect characters until the next time you see Web_797, not all the way until the last time you see Web_797. By default, the matches are "greedy" taking the biggest possible match. If we use
pattern = "Web_797-.*?Web_797" the ? turns off greedy matching so that it only matches to the next Web_797.

Regarding Applying validation in textbox through Regular Expression

I am trying to apply validation in Textbox control for limiting empty space in control. Following is the Regular Expression code I'm using:
Regularexpression validationexpression="^[^-\s][a-zA-Z0-9_\s-]+$" errortext="" />
Now my requirement is:
User should not enter empty space in begining. (Working fine)
Textbox limit is upto 10 numbers, user will able to enter as much as number he wants, no validation if he enter less than 10 numbers. (Working fine.)
validation should prompt if user enter the numbers like this "111
111 ", means show validation if there is empty space between
numbers. (Not working)
Currently I'm using following Regular Expression to achieve this thing, please let me know or update my regular expression so I can achieve this requirement.
Regularexpression validationexpression="^[^-\s][a-zA-Z0-9_\s-]+$" errortext="" />
^[a-zA-Z0-9_-]{1,10}$
Try this.See demo.
http://regex101.com/r/wQ1oW3/23
you can use a regex like
^[^\s][\d\w_-]{1,10}$
which will match as
http://regex101.com/r/lK4pF7/1
how it works?
^ asserts the pattern at the begining of the string.
[^\s] negation of \s validates those without an empty string at the begining
[\d\w_-] ensures that body contains only alphanum, _, - no spaces.
{1,10} minimum 1 and maximum 10 mathes, ensures length not greater than 10
$ asserts the pattern at end of string

Justify text according to a size as opposed to string length? ASP.NET

I have listbox with text in it, and I was asked to see if I could just justify its contents after the dash. My resulting code produced something like this:
Which works fine for scenarios where the text to the left of the dash is less than the max length found from the other items in the listbox (i.e. (B20) is less than (B15-B19), which is the longest entry found, so add some whitespace before the dash).
The issue, though, is that if the text before the dash is same length, it still looks like it isn't justified. Example:
Is there a way to truly line up all the dashes? I would imagine I would have to look at the actual pixel length of the characters before the dash as opposed to the length?
Notes:
I am using ASP.NET Webforms
VB.NET
The text for each item in the listbox is all one string
Right now, my method to accomplish what you see in the first picture is as follows:
Public Sub JustifyDisplayName()
Const ACCOUNT_FOR_DASH As Integer = 4
Dim maxCharCount As Integer = 0
Dim whiteSpace As String = HttpUtility.HtmlDecode(" ")
'Find which one is the longest code
For Each element As TextEntry In Me
If element.Value.Length > maxCharCount Then
maxCharCount = element.Value.Length
End If
Next
'Now, extend the '-' to the max for all items
For Each element As TextEntry In Me
'See how much white space we need to inject
Dim paddingNeeded As Integer = maxCharCount - element.Value.Length
Dim tempDisplay As StringBuilder = New StringBuilder(element.Value)
If paddingNeeded > 0 Then
tempDisplay.Append(CChar(whiteSpace), paddingNeeded + ACCOUNT_FOR_DASH)
tempDisplay.Append(" - " & element.Description)
End If
tempDisplay.Append(" - " & element.Description)
element.DrillDownDisplayNameJustified = tempDisplay.ToString()
Next
End Sub
Thanks.
If you used a fixed-width font, you could make this all much easier. In addition to good ol' Courier, I believe there are others.
If you don't, you're not going to be able to get exactly the right width. You could get close, but you won't get it exactly, because the difference in length between (H60-H95) and (I00-I99) as they are rendered may not evenly divide into increments of one .
But if you really want to give this a try, you'll have to use the System.Drawing namespace, the Graphics class, and a method on Graphics called MeasureString. This will be just to get the lengths of the strings in your selected font, though: System.Drawing doesn't apply to web apps.
If you could append spaces to short items before the dash so that you always have the same number of characters before the dash, you may consider using Monospaced Fonts, where each character occupies the same width - Ref: Similar Question.

How to filter two values for given single search?

How to show two records for given single search?
UI page contains millions of records.I need to show only two records instead of giving
single search.
using OR SEARCH or whatever use.I want to show two records.
And how can i give two values in single text box?
That dependa on you only, you can make use of some special charater to break two string like : or | so that you allow to etner two string like "abc|5678" than in back end you break this string in two string string1 = abc and string2=5678
Two values in single text box:
txt.Text = "value1" + "value2";

Text box validation using regular expression

I have a textbox and have to use the regular expressions in asp.net
My text should not allow the spaces in first and last place. In between words it can allow.
that means: it should allow alphabets, numbers and all special characters.
Output should be:
India Bangalore -valid
India Bangalore - not valid
!India bangalore - valid
India bangalore!##$%- valid
IndiaBangalore - valid
i.e : use can enter the spaces in between the words but not in first position and last position.
Java script also fine.
Thanks in advance.
Here is a quick example
// Input string
string st = " This is an example string. ";
// Call Trim instance method.
// This returns a new string copy.
st = st.Trim();
U can get the index, i mean index(0) is the first position of textbox and calculate the length of ur input +1 = last index of ur input validate white space validation now. damn sure it will work

Resources