如何从字符串中删除$符号

时间:2015-10-14 23:01:59

标签: vb.net string-function

我正在尝试使用货币格式开头的“$”格式化货币。

我该怎么做?我试过这个,但它不起作用:

#include <vector>
#include <iostream>

struct MemoryManager
{
    static void* allocate( unsigned size )
    {
        static char block[256];
        return block;
    }
};

class Foo
{
public:
    void* operator new[]( size_t size )
    {
        std::cout << "operator new[] : data size -- " << size << std::endl;
        return MemoryManager::allocate( size );
    }  

private:
    std::vector<long> m_dummy;  // Huh?
    unsigned m_num;
};

int main( int argc, char * argv[] )
{
    std::cout << "Foo size: " << sizeof( Foo ) << std::endl;
    new Foo [4];
    Foo::operator new[]( 4 * sizeof( Foo ) );
}

我知道$ 1,234是:

let fetch = CNContactFetchRequest(...)
fetch.sortOrder = .UserDefault

但我想删除

  

$

在货币面前。

2 个答案:

答案 0 :(得分:0)

Dim value As Double = e.Row.Cells(7).Text 
Dim val2 As String
val2 = (value.ToString("#,#", CultureInfo.InvariantCulture))
e.Row.Cells(7).Text = String.Format(CultureInfo.InvariantCulture, "{0:#,#}", val2)
  

不要忘记Imports System.Globalization

答案 1 :(得分:0)

TrimStart()功能

Dim strVal As String = "$1,234"
strVal = strVal.TrimStart("$")

replace()功能

Dim strVal As String = "$1,234"
strVal = strVal.Replace("$",String.Empty)

你可以像这样使用

e.Row.Cells(7).Text = e.Row.Cells(7).Text.TrimStart("$")

e.Row.Cells(7).Text = e.Row.Cells(7).Text.Replace("$",String.Empty)