Showing posts with label declare. Show all posts
Showing posts with label declare. Show all posts

Saturday, March 31, 2012

string variable containing one doublequote

hallo,

how do I declare a string variable containing one doublequote?

this sentence should be in the variable: <img src="http://pics.10026.com/?src=

I was trying something ilke

Dim Path as string = "<img src="http://pics.10026.com/?src= & """ but doesn' work

any idea? thanks

reply to myself: found out the solution

chr(34) instead of """


Dim Path as string = "<img src="http://pics.10026.com/?src= & """"

'/

Dim Path as string = "<img src="http://pics.10026.com/?src=""

'/

Dim Path as string = "<img src="http://pics.10026.com/?src= & Chr(34)

:)

Monday, March 26, 2012

String.Split with multi character delimiter

The Split method of the String class takes an array of char as it's
parameter. Rather than declaring a String, you need to declare a char array,
and work with that. Example:

Dim delString As String = "#|#"
Dim del As Char() = delString.ToCharArray()

...

s = source.Split(del)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"PCK" <anonymous@dotnet.itags.org.discussions.microsoft.com> wrote in message
news:3CCCD026-B1BB-4F2D-8DE2-7D3BD398127F@dotnet.itags.org.microsoft.com...
> Hi,
> I have a string that I would like split into a single dimension string
array. The source string has a multi character delimiter. It appears that
string.split(delimiter) only splits based on the first character of the
delimiter.
> For example:
> Dim s() As String
> Dim source As String
> Dim del As String
> del = "#!#"
> source = "ABC#!#DEF#!#GHI"
> s = source.Split(del)
> s(0) = "ABC"
> s(1) = "!"
> s(2) = "DEF"
> s(3) = "!"
> s(4) = "GHI"
> Where as I would like the following returned. Does anyone know of a built
in function to do this?
> s(0) = "ABC"
> s(1) = "DEF"
> s(2) = "GHI"
> Thanks.
> PCKKevin, thanks for the response

I had thought about that earlier. Actually what happens when you use a char array is that it splits based on any item in the array not on the concatenation of all items in the array

Do you have any other suggestions.
myString.Replace( "#!#", "!" ).Split ( "!" ); ?

Dan.

"PCK" <anonymous@.discussions.microsoft.com> wrote in message
news:3F0E32B3-4C65-4AA2-A1A2-110F0644FA6A@.microsoft.com...
Kevin, thanks for the response.

I had thought about that earlier. Actually what happens when you use a char
array is that it splits based on any item in the array not on the
concatenation of all items in the array.

Do you have any other suggestions.
> I had thought about that earlier. Actually what happens when you use a
char array is that it splits based on any item in the array not on the
concatenation of all items in the array.

Oops. Sorry. That's true. Well, you could always use the Visual Basic.Net
Split() method (function), which takes a string as an argument.
Alternatively, you could try Daniel's solution.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"PCK" <anonymous@.discussions.microsoft.com> wrote in message
news:3F0E32B3-4C65-4AA2-A1A2-110F0644FA6A@.microsoft.com...
> Kevin, thanks for the response.
> I had thought about that earlier. Actually what happens when you use a
char array is that it splits based on any item in the array not on the
concatenation of all items in the array.
> Do you have any other suggestions.
the problem is the split method is not intended for use with string
seperators, to do one that works properly, you'd have to write one yourself.

alternatively, if there is a character you know (think highly likely) will
NOT appear in your text, use the replace method to convert to that character
as a seperator, then split.

hope that helps.
Dan.

"PCK" <anonymous@.discussions.microsoft.com> wrote in message
news:A6A5A7D8-5BB1-46D7-BC35-ABD8DD55130E@.microsoft.com...
Dan, thanks for the response.

But what if the data was "ABC#!#D!EF#!#GHI"

That would split it out as

ABC
D
EF
GHI

versus

ABC
D!EF
GHI
The VB Split method is what I was looking for. Thanks for the help.

StringBuilder

can anyone tell me how to declare a stringbuilder using vb in visual studio, I am trying to use a stringbuilder in the following code, but visual studio states stringbuilder is not defined.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.StringBuilder

Public Class datagrid2
Inherits System.Web.UI.Page

Public Sub UpdateCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

Dim sb1 As StringBuilder = New StringBuilder("")
sb1.Append("INSERT Employees (firstname, lastname, titleofcourtesy, title, country) VALUES(")
sb1.Append("@dotnet.itags.org.sFirstName, @dotnet.itags.org.sLastName, @dotnet.itags.org.sTitle, @dotnet.itags.org.sPosition, @dotnet.itags.org.sCountry)")
cmd.CommandText = sb1.ToString()Hi,

Dim sb1 As System.Text.StringBuilder = New System.Text.StringBuilder("")

HTH
Imports System.Text.StringBuilder <-- don't do this, StringBuilder is a class, not a namespace.

use:
Imports System.Text

now you can use "StringBuilder" in your code (instead of having to write the fully qualified version of it each time)
thanks guys