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

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 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: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

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

Postby TJ » 07 Dec 2012

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.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

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

Postby arjfca » 08 Dec 2012

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


Return to “MultiCharts”