Android:将.extensions转换为Lower / Upper case

时间:2017-06-16 07:25:05

标签: android json string extension-methods

Tnx提前帮助。我想将我的点文件扩展名从大写字母转换为小写字母。例如: ABCD.JPG>> ABCD.jpg,xyz.PNG>> xyz.png

 if ( attachemtnDescription.toString().endsWith(".JPG") || attachemtnDescription.toString().endsWith(".jpg"))  {
                                        attachmentPreviewImg.setImageResource(R.drawable.ic_support_attachment_image);

因为我有很多附件类型要声明,所以在大写和小写的情况下声明所有类型的附件是忙乱的,所以我想减少我的代码。

我有一种方法可以转换上/下转换但如何实现相同的 ...请帮助相同。

EditText edit = (EditText)findViewById(R.id.email);

String input;

input = edit.getText().toString();
input = input.toLowerCase(); //converts the string to lowercase
   or 
input = input.toUpperCase(); 

2 个答案:

答案 0 :(得分:3)

我已经用过这个,希望它也会帮助你们。

describe('Select', () => {
  it('calls the onChange if the value of select changes', () => {
    const onChange = jest.fn();
    onChange= sinon.spy();
    const wrapper = mount(<Select options={options} onChange={onChange} 
     />)
    wrapper.simulate('change')
    expect(onChange.called).toEqual(true);
         });
       })



  describe('MyComponent', () => {
    it('check select component exists', () => {
        const onChange = jest.fn()
      const options = {
       enumOptions: [
        {
          label: 'Foo',
          value: 'foo'
        },
        {
          label: 'Bar',
          value: 'bar'
        }
      ]
     }

    const wrapper = mount(<MyComponent options={options} onChange=
     {onChange} />)
     const select = wrapper.find('select')
     select.length.toEqual('1');

   });
  })

使用&#34; .toLowerCase()&#34;或&#34; .toUpperCase()&#34;

答案 1 :(得分:1)

一个简单的attachemtnDescription.toString().toUpperCase().endsWith(".JPG")将解决您的问题,在进行比较之前将文件名转换为大写/小写。

相关问题