• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Count length of string before unique character appears

I'm looking for some simple vb code that will count the length of text in a string before the ":" symbol appears.

Regards
Antonio
0
cbsbutler
Asked:
cbsbutler
1 Solution
 
DhaestCommented:
You can use the instr-function

position = InStr("abc:def", ":") - 1

http://www.aivosto.com/vbtips/instr.html
0
 
skrgaCommented:
Dim strText As String
strText = "test:123"

Debug.Print Int(InStr(1, strText, ":", vbTextCompare)) - 1
0
 
Den_HBRCommented:
VB6:
MsgBox (InStr("ThisTextIs16Long:AndHereSomeMoreText", ":")) - 1

VB.NET:
MsgBox("ThisTextIs16Long:AndHereSomeMoreText".IndexOf(":"))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now