-
May 2nd, 2019, 02:03 PM
#1
Thread Starter
Fanatic Member
Remove "'"
I have tried the following:
Initial value = 5'
Code:
If strValue.Contains(Chr(39)) Then
strValue = strValue.Replace(Asc(39), "").Trim
End If
If strValue.Contains(Asc(39)) Then
strValue = strValue.Replace(Chr(39), "").Trim
End If
If strValue.Contains("'") Then
strValue = strValue.Replace("'", "").Trim
End If
I'm assuming the difficulty is that there is already a ' somewhere in the interpretation, since it is a string.
Thanks!
Last edited by ssabc; May 3rd, 2019 at 08:14 AM.
-
May 2nd, 2019, 02:13 PM
#2
Re: Remove "'"
So, what is the issue? Is it not removing the apostrophe / single quote? Are you sure that the character in your actual string is really an ASCII 39 value? There are other similar characters with different ASCII values.
-
May 2nd, 2019, 02:34 PM
#3
Re: Remove "'"
you could do
Code:
Dim str As String = "this is a '"
If str.Contains("'") Then
str = str.Replace("'"c, "")
End If
or
Code:
Dim str As String = "this is a '"
If str.Contains("'") Then
str = str.Replace("'", "")
End If
Why are you removing it? Is it by chance you are trying to insert/update this value in a database?
-
May 2nd, 2019, 07:05 PM
#4
Re: Remove "'"
Asc() is to get the code from a chr ... I think you mean Chr(), this gets the chr from the code...
You should turn Option Strict On and you would realize this...
Also you should not check against one thing and then use another to replace ... just use "'" to replace if you are using "'" to check.
Kris
-
May 3rd, 2019, 08:17 AM
#5
Thread Starter
Fanatic Member
Re: Remove "'"
The value is simply text. If the variable contains a "'", I want to get rid of it. It resides in a data grid view, manually created, no data binding...
-
May 3rd, 2019, 09:46 AM
#6
Re: Remove "'"
Please show where StrValue gets it's initial value.
-
May 3rd, 2019, 11:16 AM
#7
Re: Remove "'"
I wonder if it's really a ` and not a '
-tg
-
May 3rd, 2019, 12:13 PM
#8
Re: Remove "'"
His OP uses ' for checking, either we are getting trolled or there is something else wrong, such as the input to the strValue isnt what he expects it to be.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|