How to count how many comma in a CSV string  [SOLVED]

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

How to count how many comma in a CSV string

Postby arjfca » 07 Dec 2012

Hello

How can i count the number of comma (",") in a a CSV string: Comma separated String

Any help appreciated

Martin

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: How to count how many comma in a CSV string  [SOLVED]

Postby TJ » 07 Dec 2012

arjfca wrote:Hello

How can i count the number of comma (",") in a a CSV string: Comma separated String

Any help appreciated

Martin


first, find out the length of the string (hint: there is a keyword for that),
then create a loop that cycles the length of the string,
during the cycle through the loop, check each character to see if it is a ",".
Count while you are do the matching.
These users thanked the author TJ for the post (total 2):
JoshMarjfca

arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Re: How to count how many comma in a CSV string

Postby arjfca » 08 Dec 2012

TJ wrote:
arjfca wrote:Hello

How can i count the number of comma (",") in a a CSV string: Comma separated String

Any help appreciated

Martin


first, find out the length of the string (hint: there is a keyword for that),
then create a loop that cycles the length of the string,
during the cycle through the loop, check each character to see if it is a ",".
Count while you are do the matching.


Here is a code

Code: Select all

Var:
A (0),
B (1),
Str ("A,B,C,D");

While B <> 0 begin
   B= Instr(STR,B,",");
   If B <> 0 then begin
        A= A+1;
        B = B +1;
   end;
end;

// A = Number of comma

Here is a code In Excel

Code: Select all

Sub Countcomma_2()
Dim a As Integer
Dim Str As String
Dim b As Integer
b = 1
Str = ("A,B,C,D")

While b <> 0
   b = InStr(b, Str, ",")
   If b <> 0 Then
        a = a + 1
        b = b + 1
   End If
Wend
MsgBox a
These users thanked the author arjfca for the post:
JoshM


Return to “MultiCharts”