SgDotNet
Singapore Professional .NET User Group -For Cool Developers

A vb question related to string..

rated by 0 users
This post has 10 Replies | 1 Follower

Top 200 Contributor
Posts 9
angelhalo Posted: 06-14-2005 11:59 AM

For java  there is String.CharAt(0) , to take the 1st char of the string (correct me if the syntax is wrong)

is there a similar method in vbScript / vb ?

Top 25 Contributor
Posts 442

VB has many string manipulation functions.

Left(strOrigin, intLen) will extract the given number of  left most characters from the given string.

Right(strOrigin, intLen) will extract the given number of right most characters from the given string.

Mid(strOrigin, intStart, intLen) will extract the intLen of characters from the strOrigin starting from intStart index.

If you are using VB.NET 2005, you have to call these functions thru Strings module of the Microsoft.VisualBasic library (which is already referenced by your VB Project).

For Example:

Dim s as String = "Hello World"
MessageBox.Show(Strings.Left(s,5))

The above example will display "Hello" in the messagebox.

But remember one thing when you are playing with the string datatype.  String datatype in .NET is reference type and it is immutable.  Excessive string manipulation will have impact on the performance.  You should consider using StringBuilder if you need more complex/excessive string manipulation.

Hope it helps a little. Idea [I]

Maung Maung

Maung Maung
Top 10 Contributor
Posts 1,626
You can use Substring.
Software development made easy with Paladin RAD Framework. Save some trees, use Stickies.NET
Top 25 Contributor
Posts 442

 Firedancer wrote:
You can use Substring.

Yes, why didn't I think of that? Embarrassed [:$]

Using .NET Framework provided method are better in term of langauge portability.

You can find out the static methods of the String class in Object Browser.

Maung Maung

 

Maung Maung
Top 200 Contributor
Posts 9

hmm substring would be nice but too bad i'm doing vbscript which doesn't has this function ( I thought that it might have it ) ..

Anyway i need to break a string into many characters.. e.g using split, u can split the expression into many pieces stored in an array ( this pieces are seperated by a delimeter)

e.g t.e.s.t and the delimeter is "." , this string will be seperated into t, e, s, t...

I need to find a way that can do the same thing but without the use of adding "."

Can someone add a vbscript page in this forum ? (lol) I feel abit awkward asking vbscript questions in VB.NET page..lol

Top 10 Contributor
Posts 2,284
 angelhalo wrote:
hmm substring would be nice but too bad i'm doing vbscript which doesn't has this function ( I thought that it might have it ) ..
The equivalent in VB or VBscript is the Mid() function.

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Top 25 Contributor
Posts 442
 angelhalo wrote:

hmm substring would be nice but too bad i'm doing vbscript which doesn't has this function ( I thought that it might have it ) ..

Anyway i need to break a string into many characters.. e.g using split, u can split the expression into many pieces stored in an array ( this pieces are seperated by a delimeter)

e.g t.e.s.t and the delimeter is "." , this string will be seperated into t, e, s, t...

I need to find a way that can do the same thing but without the use of adding "."

Can someone add a vbscript page in this forum ? (lol) I feel abit awkward asking vbscript questions in VB.NET page..lol

Oh i c Geeked [8-|], you are doing the VB Scripting.  Then you can reference the first post which I replied earlier as those functions can be used in VB Scripting as well as .NET programming.

Maung Maung

Maung Maung
Top 200 Contributor
Posts 9

oh you mean the messagebox.show ? ok thx..

btw, out of topic qn, is there any attachment students using this forum ?? (I'm one lol..)

Top 25 Contributor
Posts 442

MessageBox.Show is the VB.NET thingy. So just stick to MsgBox for VBScripting or Wscript.Echo() method to display it.

Maung Maung

Maung Maung
Top 10 Contributor
Posts 2,284
 angelhalo wrote:
btw, out of topic qn, is there any attachment students using this forum ?? (I'm one lol..)
While there are student-oriented forums in this community, we generally do not differentiate the "age groups" and push students into a nursery room. We are all here because of .NET, that's it.

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Top 200 Contributor
Posts 9

MuangMaung : k thanks for da help

Icelava : ok =x I was just asking for fun, anyway i didn't notice there is a student-oriented forum o.o I'll go check it out when im free..back to work

Page 1 of 1 (11 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems