Remove what is second parentheses of a string vb.net
up vote
0
down vote
favorite
i have a string like this
blabla (lo-g) (kk-jj)
i want to make it like this
blabla (lo-g)
but when it's already like this in vb.net
blabla (lo-g) with one parenteses
just let it as and is
thanks
asp.net vb.net trim
add a comment |
up vote
0
down vote
favorite
i have a string like this
blabla (lo-g) (kk-jj)
i want to make it like this
blabla (lo-g)
but when it's already like this in vb.net
blabla (lo-g) with one parenteses
just let it as and is
thanks
asp.net vb.net trim
What would you want to happen with strings likeblabla (lo-g) with (kk-jj) trailing
andblabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i have a string like this
blabla (lo-g) (kk-jj)
i want to make it like this
blabla (lo-g)
but when it's already like this in vb.net
blabla (lo-g) with one parenteses
just let it as and is
thanks
asp.net vb.net trim
i have a string like this
blabla (lo-g) (kk-jj)
i want to make it like this
blabla (lo-g)
but when it's already like this in vb.net
blabla (lo-g) with one parenteses
just let it as and is
thanks
asp.net vb.net trim
asp.net vb.net trim
asked Nov 9 at 16:17
Otmane Hatiji
135
135
What would you want to happen with strings likeblabla (lo-g) with (kk-jj) trailing
andblabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27
add a comment |
What would you want to happen with strings likeblabla (lo-g) with (kk-jj) trailing
andblabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27
What would you want to happen with strings like
blabla (lo-g) with (kk-jj) trailing
and blabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27
What would you want to happen with strings like
blabla (lo-g) with (kk-jj) trailing
and blabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
i want to thanks steven for his answer but for those who can't handle regex (like me)
here's a simple stupid method
Dim res As String = String.Empty
Dim check As Boolean = False
For Each letter In teamname
If letter = "(" Then
If check = True Then
Exit For
End If
check = True
End If
res &= letter
Next
Return res
good luck
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
add a comment |
up vote
0
down vote
Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:
Dim input As String = "blabla (lo-g) (kk-jj)"
Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
Dim output As String = Regex.Replace(input, pattern, "")
However, that will not remove the second set of parenthesis for inputs like these:
blabla (lo-g) blabla (kk-jj) blabla
blabla (lo-g) (kk-jj) blabla
To handle variations like those, you could use a pattern like this:
Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
Dim output As String = Regex.Replace(input, pattern, "")
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
add a comment |
up vote
0
down vote
Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).
Essentially splitting your string into this:
"blabla (lo-g) (kk-jj)"
Array(0) = "blabla "
Array(1) = "lo-g) "
So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character
Dim SplitText = text.Split("(")
If SplitText.Length > 1 Then
Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
'This may be easier for you to read, though:
'Return text.Split("(")(0) & "(" & text.Split("(")(1)
End If
Return text
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
i want to thanks steven for his answer but for those who can't handle regex (like me)
here's a simple stupid method
Dim res As String = String.Empty
Dim check As Boolean = False
For Each letter In teamname
If letter = "(" Then
If check = True Then
Exit For
End If
check = True
End If
res &= letter
Next
Return res
good luck
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
add a comment |
up vote
1
down vote
i want to thanks steven for his answer but for those who can't handle regex (like me)
here's a simple stupid method
Dim res As String = String.Empty
Dim check As Boolean = False
For Each letter In teamname
If letter = "(" Then
If check = True Then
Exit For
End If
check = True
End If
res &= letter
Next
Return res
good luck
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
add a comment |
up vote
1
down vote
up vote
1
down vote
i want to thanks steven for his answer but for those who can't handle regex (like me)
here's a simple stupid method
Dim res As String = String.Empty
Dim check As Boolean = False
For Each letter In teamname
If letter = "(" Then
If check = True Then
Exit For
End If
check = True
End If
res &= letter
Next
Return res
good luck
i want to thanks steven for his answer but for those who can't handle regex (like me)
here's a simple stupid method
Dim res As String = String.Empty
Dim check As Boolean = False
For Each letter In teamname
If letter = "(" Then
If check = True Then
Exit For
End If
check = True
End If
res &= letter
Next
Return res
good luck
answered Nov 9 at 17:20
Otmane Hatiji
135
135
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
add a comment |
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
– Mary
Nov 9 at 17:40
add a comment |
up vote
0
down vote
Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:
Dim input As String = "blabla (lo-g) (kk-jj)"
Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
Dim output As String = Regex.Replace(input, pattern, "")
However, that will not remove the second set of parenthesis for inputs like these:
blabla (lo-g) blabla (kk-jj) blabla
blabla (lo-g) (kk-jj) blabla
To handle variations like those, you could use a pattern like this:
Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
Dim output As String = Regex.Replace(input, pattern, "")
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
add a comment |
up vote
0
down vote
Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:
Dim input As String = "blabla (lo-g) (kk-jj)"
Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
Dim output As String = Regex.Replace(input, pattern, "")
However, that will not remove the second set of parenthesis for inputs like these:
blabla (lo-g) blabla (kk-jj) blabla
blabla (lo-g) (kk-jj) blabla
To handle variations like those, you could use a pattern like this:
Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
Dim output As String = Regex.Replace(input, pattern, "")
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
add a comment |
up vote
0
down vote
up vote
0
down vote
Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:
Dim input As String = "blabla (lo-g) (kk-jj)"
Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
Dim output As String = Regex.Replace(input, pattern, "")
However, that will not remove the second set of parenthesis for inputs like these:
blabla (lo-g) blabla (kk-jj) blabla
blabla (lo-g) (kk-jj) blabla
To handle variations like those, you could use a pattern like this:
Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
Dim output As String = Regex.Replace(input, pattern, "")
Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:
Dim input As String = "blabla (lo-g) (kk-jj)"
Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
Dim output As String = Regex.Replace(input, pattern, "")
However, that will not remove the second set of parenthesis for inputs like these:
blabla (lo-g) blabla (kk-jj) blabla
blabla (lo-g) (kk-jj) blabla
To handle variations like those, you could use a pattern like this:
Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
Dim output As String = Regex.Replace(input, pattern, "")
edited Nov 9 at 16:53
answered Nov 9 at 16:46
Steven Doggart
37.4k44084
37.4k44084
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
add a comment |
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
thank you these regex work very well for me, but i didn't understand them that's why i create my own method
– Otmane Hatiji
Nov 9 at 17:22
add a comment |
up vote
0
down vote
Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).
Essentially splitting your string into this:
"blabla (lo-g) (kk-jj)"
Array(0) = "blabla "
Array(1) = "lo-g) "
So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character
Dim SplitText = text.Split("(")
If SplitText.Length > 1 Then
Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
'This may be easier for you to read, though:
'Return text.Split("(")(0) & "(" & text.Split("(")(1)
End If
Return text
add a comment |
up vote
0
down vote
Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).
Essentially splitting your string into this:
"blabla (lo-g) (kk-jj)"
Array(0) = "blabla "
Array(1) = "lo-g) "
So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character
Dim SplitText = text.Split("(")
If SplitText.Length > 1 Then
Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
'This may be easier for you to read, though:
'Return text.Split("(")(0) & "(" & text.Split("(")(1)
End If
Return text
add a comment |
up vote
0
down vote
up vote
0
down vote
Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).
Essentially splitting your string into this:
"blabla (lo-g) (kk-jj)"
Array(0) = "blabla "
Array(1) = "lo-g) "
So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character
Dim SplitText = text.Split("(")
If SplitText.Length > 1 Then
Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
'This may be easier for you to read, though:
'Return text.Split("(")(0) & "(" & text.Split("(")(1)
End If
Return text
Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).
Essentially splitting your string into this:
"blabla (lo-g) (kk-jj)"
Array(0) = "blabla "
Array(1) = "lo-g) "
So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character
Dim SplitText = text.Split("(")
If SplitText.Length > 1 Then
Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
'This may be easier for you to read, though:
'Return text.Split("(")(0) & "(" & text.Split("(")(1)
End If
Return text
answered Nov 10 at 15:49
Nathan Champion
2269
2269
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229469%2fremove-what-is-second-parentheses-of-a-string-vb-net%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What would you want to happen with strings like
blabla (lo-g) with (kk-jj) trailing
andblabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27